我试图在你触摸屏幕时让身体移动。如果从精灵向左触摸则向左,如果向右触摸则向右。 我遇到的错误是身体只移动一段距离,该距离等于从Sprite的触摸距离。
我理解的解决方法是通过当前相机位置修改触摸事件
以下所有代码walkingActivate=true;
Sprite onManageUpdate
@Override
protected void onManagedUpdate(float pSecondsElapsed) {
super.onManagedUpdate(pSecondsElapsed);
if(walkingActivate) {
if (mActivity.touchedForWaling) {
if (!characterImage.isAnimationRunning()) {
characterImage.animate(new long[]{200,200,200,200,200},new int[]{1,2,3,4,5},true);
}
move(mActivity.SceneTouchEvent);
}
else{
characterImage.stopAnimation();
characterImage.setCurrentTileIndex(0);
}
}
}
相关代码
public void move(TouchEvent event){
float movement=.05f;
if (event.getX()+mActivity.mCamera.getXMin()<characterImage.getX()){
movement=-.05f;
characterImage.setFlippedHorizontal(true);
}
else {characterImage.setFlippedHorizontal(false);}
PlayerBody.setTransform(PlayerBody.getPosition().x+movement,PlayerBody.getPosition().y,0);
}
场景监听器的一部分
if(currentPlayer.walkingActivate) {
mCamera.setChaseEntity(currentPlayer.characterImage);
if((!currentPlayer.onAir)&&(pSceneTouchEvent.isActionDown()||pSceneTouchEvent.isActionMove())){
SceneTouchEvent= pSceneTouchEvent;
Log.d("DEBUG","TouchEvent changed");
//this will trigger the walking action in the Sprite onUpdate
touchedForWaling =true;
}
else {touchedForWaling =false;}
XMin方法不起作用所以我不知道还有什么可以尝试(除了getCenterX()-getWithd/2