auto ground = Sprite::create("sky.jpg");
ground->setPosition(visibleSize / 2);
addChild(ground);
auto hero = Sprite::create("kick1.png");
hero->setPosition(visibleSize / 2);
addChild(hero);
Animation *animation = Animation::create();
//从本地文件系统中加载图片文件到CCSpriteFrame中区,然后添加到CCAnimation中
for (int i = 1; i < 5; i++)
{
char szImageFileName = { 0 };
sprintf(szImageFileName, "kick%d.png", i);
animation->addSpriteFrameWithFileName(szImageFileName);
}
animation->setDelayPerUnit(2.);
animation->setRestoreOriginalFrame(true);
Animate *action = CCAnimate::create(animation);
hero->runAction(action);
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = (Touch* t, Event *e)
{
hero->runAction(action);//是运行到这里出错
return false;
};
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener,ground);
是不是不能在事件侦听处理器里运行帧动画???