我正在开发像超级马里奥这样的横向卷轴游戏。我正在尝试使用setLinearVelocity()
移动角色,但这似乎无法正常工作。当角色掉落然后开始移动时,他不会继续摔倒而只会移动。
这是一段代码:
Sprite backward = new Sprite( -50, CAMERA_HEIGHT - 170, backwardr){
@Override
public boolean onAreaTouched(TouchEvent pEvent, float pX, float pY){
if(!pEvent.isActionUp()){
charactersprite.getTextureRegion().setFlippedHorizontal(true);
body.setLinearVelocity(new Vector2(3,0)); // There's the problem
}else{
body.setLinearVelocity(new Vector2(0,0)); // Don't look at there
}
return false;
}
};
有人可以帮助我吗?
答案 0 :(得分:1)
我修复了:
Sprite backward = new Sprite( -50, CAMERA_HEIGHT - 170, backwardr){
@Override
public boolean onAreaTouched(TouchEvent pEvent, float pX, float pY){
if(!pEvent.isActionUp()){
charactersprite.getTextureRegion().setFlippedHorizontal(true);
body.setLinearVelocity(new Vector2(3,body.getLinearVelocity.y)); // There's the problem
}else{
body.setLinearVelocity(new Vector2(0,getLinearVelocity.y)); // Don't look at there
}
return false;
}
};