mirror of https://github.com/axmolengine/axmol.git
parent
000bdeeb42
commit
a882532e28
|
@ -37,6 +37,7 @@ OBJECTS = \
|
|||
$(OBJECTS_DIR)/TG3AppDllEntry.o \
|
||||
$(OBJECTS_DIR)/controller.o \
|
||||
$(OBJECTS_DIR)/testBasic.o \
|
||||
$(OBJECTS_DIR)/AccelerometerTest.o \
|
||||
$(OBJECTS_DIR)/ActionManagerTest.o \
|
||||
$(OBJECTS_DIR)/ActionsTest.o \
|
||||
$(OBJECTS_DIR)/AtlasTest.o \
|
||||
|
@ -125,6 +126,9 @@ $(OBJECTS_DIR)/controller.o : ./tests/controller.cpp
|
|||
$(OBJECTS_DIR)/testBasic.o : ./tests/testBasic.cpp
|
||||
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/testBasic.o ./tests/testBasic.cpp
|
||||
|
||||
$(OBJECTS_DIR)/AccelerometerTest.o : ./tests/AccelerometerTest/AccelerometerTest.cpp
|
||||
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/AccelerometerTest.o ./tests/AccelerometerTest/AccelerometerTest.cpp
|
||||
|
||||
$(OBJECTS_DIR)/ActionManagerTest.o : ./tests/ActionManagerTest/ActionManagerTest.cpp
|
||||
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/ActionManagerTest.o ./tests/ActionManagerTest/ActionManagerTest.cpp
|
||||
|
||||
|
|
|
@ -879,6 +879,18 @@
|
|||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="AccelerometerTest"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\tests\AccelerometerTest\AccelerometerTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tests\AccelerometerTest\AccelerometerTest.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
#include "AccelerometerTest.h"
|
||||
#include "../testResource.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
#define FIX_POS(_pos, _min, _max) \
|
||||
if (_pos < _min) \
|
||||
_pos = _min; \
|
||||
else if (_pos > _max) \
|
||||
_pos = _max; \
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// AccelerometerTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
AccelerometerTest::AccelerometerTest(void)
|
||||
: m_fLastTime(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
AccelerometerTest::~AccelerometerTest(void)
|
||||
{
|
||||
m_pBall->release();
|
||||
}
|
||||
|
||||
std::string AccelerometerTest::title()
|
||||
{
|
||||
return "AccelerometerTest";
|
||||
}
|
||||
|
||||
void AccelerometerTest::onEnter()
|
||||
{
|
||||
CCLayer::onEnter();
|
||||
|
||||
setIsAccelerometerEnabled(true);
|
||||
|
||||
CGSize s = CCDirector::getSharedDirector()->getWinSize();
|
||||
|
||||
CCLabel* label = CCLabel::labelWithString(title().c_str(), "Arial", 32);
|
||||
addChild(label, 1);
|
||||
label->setPosition( CGPointMake(s.width/2, s.height-50) );
|
||||
|
||||
m_pBall = CCSprite::spriteWithFile("Images/ball.png");
|
||||
m_pBall->setPosition(ccp(s.width / 2, s.height / 2));
|
||||
addChild(m_pBall);
|
||||
|
||||
m_pBall->retain();
|
||||
}
|
||||
|
||||
void AccelerometerTest::didAccelerate(UIAcceleration* pAccelerationValue)
|
||||
{
|
||||
// double fNow = pAccelerationValue->timestamp;
|
||||
//
|
||||
// if (m_fLastTime > 0.0)
|
||||
// {
|
||||
// CGPoint ptNow = convertToUI
|
||||
// }
|
||||
//
|
||||
// m_fLastTime = fNow;
|
||||
|
||||
CCDirector* pDir = CCDirector::getSharedDirector();
|
||||
CGSize winSize = pDir->getWinSize();
|
||||
CGSize ballSize = m_pBall->getContentSize();
|
||||
|
||||
CGPoint ptNow = m_pBall->getPosition();
|
||||
CGPoint ptTemp = pDir->convertToUI(ptNow);
|
||||
|
||||
ptTemp.x += pAccelerationValue->x * TG3_GRAVITY_EARTH;
|
||||
ptTemp.y -= pAccelerationValue->y * TG3_GRAVITY_EARTH;
|
||||
|
||||
CGPoint ptNext = pDir->convertToGL(ptTemp);
|
||||
FIX_POS(ptNext.x, (ballSize.width / 2.0), (winSize.width - ballSize.width / 2.0));
|
||||
FIX_POS(ptNext.y, (ballSize.height / 2.0), (winSize.height - ballSize.height / 2.0));
|
||||
m_pBall->setPosition(ptNext);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// AccelerometerTestScene
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void AccelerometerTestScene::runThisTest()
|
||||
{
|
||||
CCLayer* pLayer = new AccelerometerTest();
|
||||
addChild(pLayer);
|
||||
pLayer->release();
|
||||
|
||||
CCDirector::getSharedDirector()->replaceScene(this);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef _ACCELEROMETER_TEST_H_
|
||||
#define _ACCELEROMETER_TEST_H_
|
||||
|
||||
#include "../testBasic.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
class AccelerometerTest: public CCLayer
|
||||
{
|
||||
protected:
|
||||
CCSprite* m_pBall;
|
||||
double m_fLastTime;
|
||||
|
||||
public:
|
||||
AccelerometerTest(void);
|
||||
~AccelerometerTest(void);
|
||||
|
||||
virtual void didAccelerate(UIAcceleration* pAccelerationValue);
|
||||
|
||||
virtual std::string title();
|
||||
virtual void onEnter();
|
||||
};
|
||||
|
||||
class AccelerometerTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -70,6 +70,8 @@ static TestScene* CreateTestScene(int nIdx)
|
|||
pScene = new EffectAdvanceScene(); break;
|
||||
case TEST_HIRES:
|
||||
pScene = new HiResTestScene(); break;
|
||||
case TEST_ACCELEROMRTER:
|
||||
pScene = new AccelerometerTestScene(); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "Box2DTestBed/Box2dView.h"
|
||||
#include "EffectsAdvancedTest/EffectsAdvancedTest.h"
|
||||
#include "HiResTest/HiResTest.h"
|
||||
#include "AccelerometerTest/AccelerometerTest.h"
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -60,6 +61,7 @@ enum
|
|||
TEST_BOX2DBED,
|
||||
TEST_EFFECT_ADVANCE,
|
||||
TEST_HIRES,
|
||||
TEST_ACCELEROMRTER,
|
||||
|
||||
TESTS_COUNT,
|
||||
};
|
||||
|
@ -93,6 +95,7 @@ const std::string g_aTestNames[TESTS_COUNT] = {
|
|||
"Box2dTestBed",
|
||||
"EffectAdvancedTest",
|
||||
"HiResTest",
|
||||
"Accelerometer",
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue