我目前正在为 Android 制作 2d 游戏。
我现在在角色的移动方面遇到了麻烦。
这是我想要做的:
当我触摸左/右按钮时,英雄应该向左/右走。
如果 HERO 不在 STAGE 的中间,他应该继续步行直到到达 STAGE 的中间。
当他到达舞台中间时。我希望背景移动而不是英雄。
您能否告诉我应该如何验证代码,以便(HERO.x = 舞台中间)背景开始移动?
谢谢 :) 这是右侧按钮的代码片段,它不能按预期工作。
btnright.addEventListener(TouchEvent.TOUCH_BEGIN,onright);
addEventListener(Event.ENTER_FRAME,goright);
function onright(e:TouchEvent):void{
istouching = true;
}
function goright(e:Event):void{
if(istouching){ //if the button is touched
hero.x+=10;
hero.gotoAndStop("walking");
hero.scaleX=1;
if(hero.x == stage.stageWidth*.5){ //if HERO reaches the middle of the stage
bg.x-=5;
hero.gotoAndStop("walking");
hero.scaleX=1;
}
}
}