2010-11-18 14:50:28 +08:00
|
|
|
#include "ClickAndMoveTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2010-08-23 11:53:37 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagSprite = 1,
|
2010-11-18 14:50:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void ClickAndMoveTestScene::runThisTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = new MainLayer();
|
2010-11-18 14:50:28 +08:00
|
|
|
pLayer->autorelease();
|
|
|
|
|
|
|
|
addChild(pLayer);
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 11:53:37 +08:00
|
|
|
MainLayer::MainLayer()
|
|
|
|
{
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* sprite = Sprite::create(s_pPathGrossini);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
Layer* layer = LayerColor::create(Color4B(255,255,0,255));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(layer, -1);
|
|
|
|
|
|
|
|
addChild(sprite, 0, kTagSprite);
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite->setPosition( Point(20,150) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite->runAction( JumpTo::create(4, Point(300,48), 100, 4) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
layer->runAction( RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
FadeIn::create(1),
|
|
|
|
FadeOut::create(1),
|
2012-12-10 14:12:56 +08:00
|
|
|
NULL)
|
|
|
|
));
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void MainLayer::ccTouchesEnded(Set *pTouches, Event *pEvent)
|
2010-08-23 11:53:37 +08:00
|
|
|
{
|
2013-06-22 11:02:43 +08:00
|
|
|
Touch* touch = (Touch*) pTouches->anyObject();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Point location = touch->getLocation();
|
2010-08-23 11:53:37 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Node* s = getChildByTag(kTagSprite);
|
2012-04-19 14:35:52 +08:00
|
|
|
s->stopAllActions();
|
2013-07-12 14:11:55 +08:00
|
|
|
s->runAction( MoveTo::create(1, Point(location.x, location.y) ) );
|
2012-07-31 17:41:53 +08:00
|
|
|
float o = location.x - s->getPosition().x;
|
|
|
|
float a = location.y - s->getPosition().y;
|
2012-04-19 14:35:52 +08:00
|
|
|
float at = (float) CC_RADIANS_TO_DEGREES( atanf( o/a) );
|
|
|
|
|
|
|
|
if( a < 0 )
|
|
|
|
{
|
|
|
|
if( o < 0 )
|
|
|
|
at = 180 + fabs(at);
|
|
|
|
else
|
|
|
|
at = 180 - fabs(at);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
s->runAction( RotateTo::create(1, at) );
|
2010-08-23 11:53:37 +08:00
|
|
|
}
|