USING_NS_CC;
Scene* Fly::createScene()
{
auto scene = Scene::create();
auto layer = Fly::create();
scene->addChild(layer);
return scene;
}
bool Fly::init()
{
if (!Layer::init())
{
return false;
}
auto* background = Sprite::create(“bg_day.png”);
background->setPosition(0, 0);
background->setAnchorPoint(Vec2(0, 0));
addChild(background);
auto* bird = Sprite::create(“bird0_0.png”);
bird->setPosition(144, 256);
addChild(bird);
auto* m_frameCache = SpriteFrameCache::getInstance();
m_frameCache->addSpriteFramesWithFile(“bird.plist”, “bird.png”);
Vector<SpriteFrame*>frameArray;
for (int i = 0; i <3; i++)
{
auto* frame = m_frameCache->getSpriteFrameByName(String::createWithFormat(“bird0_%d.png”, i)->getCString());
frameArray.pushBack(frame);
}
Animation* animation = Animation::createWithSpriteFrames(frameArray);
animation->setLoops(-1);
animation->setDelayPerUnit(0.1f);
auto* action = Animate::create(animation);
bird->runAction(action);
listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(Fly::onTouchBegan, this);
listener->onTouchEnded = CC_CALLBACK_2(Fly::onTouchEnded, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
}
bool Fly::onTouchBegan(Touch* touch, Event* event)
{
CCLOG(“touch began”);
Fly::birdMove();
return false;
}
void Fly::onTouchEnded(Touch* touch, Event* event)
{
}void Fly::birdMove()
{
auto* moveto = MoveTo::create(0.5f, Vec2(144, 100));
//Action* finaction = Spawn::create(moveto, action, NULL);
bird->runAction(moveto);
}