void RenWu::AnXia(EventKeyboard::KeyCode keyc, Event* e)
{
switch (keyc)
{
case cocos2d::EventKeyboard::KeyCode::KEY_A:
MaLi_xingzou = LEFT;
{
auto animation = Animation::create();
for (int index = 24; index <= 27; index++)
{
auto str = new char[50];
std::sprintf(str, "p1_%d.png", index);
animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str));
}
animation->setDelayPerUnit(0.05f);
auto action = Animate::create(animation);
this->runAction(RepeatForever::create(action));
}
break;
case cocos2d::EventKeyboard::KeyCode::KEY_D:
MaLi_xingzou = RIGHT;
{
auto animation = Animation::create();
for (int index = 9; index <= 12; index++)
{
auto str = new char[50];
std::sprintf(str, "p1_%d.png", index);
animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str));
}
animation->setDelayPerUnit(0.05f);
auto action = Animate::create(animation);
this->runAction(RepeatForever::create(action));
}
break;
case cocos2d::EventKeyboard::KeyCode::KEY_W:
MaLi_xingzou = UP;
break;
case cocos2d::EventKeyboard::KeyCode::KEY_S:
break;
default:
break;
}
}void RenWu::update(float dt)
{
Vec2 newPos = this->getPosition();
switch (MaLi_xingzou)
{
case STOP:
break;
case LEFT:
newPos.x -= SuDu_1*dt;
break;
case RIGHT:
newPos.x += SuDu_1*dt;
break;
case UP:
break;
case LEFTUP:
break;
default:
break;
}
if (!PengZhuang::getPengZhuang()->PanDuanPengZhuang(newPos))
{
this->setPosition(newPos);
}
}
想让精灵有跳跃操作 该怎么做 求大神帮忙!!!!!!!!!!!!!!!!