enter image description here 当我单击按钮时,它将执行操作 帮我。它不起作用 SpriteFrameCache :: getInstance()-> addSpriteFramesWithFile(“ run.plist”,“ run.png”);
const int numberSprite = 6;
auto gameSprite = Sprite::createWithSpriteFrameName("run1.png");
gameSprite->setPosition(100,200);
gameSprite->setScale(2);
this->addChild(gameSprite);
Vector<SpriteFrame*> animFrames;
animFrames.reserve(numberSprite);
animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("run1.png"));
animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("run2.png"));
animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("run3.png"));
animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("run4.png"));
animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("run5.png"));
animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("run6.png"));
Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
Animate* animate = Animate::create(animation);
gameSprite->runAction(RepeatForever::create(animate));
auto button = Button::create("play.png");
button->setTitleText("");
button->setScale(0.5);
button->setPosition(visibleSize / 2);
button->addTouchEventListener([&gameSprite](Ref* sender, Widget::TouchEventType type) {
switch (type)
{
case ui::Widget::TouchEventType::BEGAN:
auto moveBy3 = MoveBy::create(30, Vec2(2000, 0));
gameSprite->runAction(moveBy3);
case ui::Widget::TouchEventType::ENDED:
break;
default:
break;
}
});
this->addChild(button, 10);