我尝试在我的精灵的更新方法中执行 RotateBy 。它只是翻译。而不是旋转。谁能告诉我怎么做?谢谢。
void CBall::Update(float dt)
{
this->Start();
auto action = RotateBy::create(dt,10);
this->runAction(action);
}
void CBall::Start()
{
float currentX = getPositionX();
float distance = currentX + xOffset;
float time = distance / _speedX;
Vec2 destination = Vec2(distance,this->getPositionY());
auto actionMove = MoveTo::create(time,destination);
this->runAction(actionMove);
if(currentX > _screenWidth)
{
ReachedEndOfScreen();
}
}
答案 0 :(得分:1)
实际上你需要使用Spawn action它会同时运行许多动作。
以下是修改后的更新功能:
void CBall::Update(float dt)
{
float currentX = getPositionX();
float distance = currentX + xOffset;
float time = distance / _speedX;
Vec2 destination = Vec2(distance,this->getPositionY());
auto actionMove = MoveTo::create(time,destination);
if(currentX > _screenWidth)
{
ReachedEndOfScreen();
}
auto actionRotate = RotateBy::create(dt,10);
this->runAction(Spawn::create(actionMove, actionRotate, nullptr));
}
我内联了你可能考虑重组组合函数中的Update实现的Start()成员函数;-)
答案 1 :(得分:0)
尝试在第一个操作中应用它,而不是在更新方法中应用其他操作。同时增加角度并减少RotateBy动作的持续时间以进行测试。
float currentX = getPositionX();
float distance = currentX + xOffset;
float time = distance / _speedX;
Vec2 destination = Vec2(distance,this->getPositionY());
auto actionMove = MoveTo::create(time,destination);
this->runAction(actionMove);
auto action = RotateBy::create(4,720);
this->runAction(action);
我希望它有所帮助。