我有一个方向和一个冲刺按钮。我想要发生的是:按住冲刺按钮时,玩家的移动速度是原来的两倍。然后当释放冲刺按钮时,玩家应该继续以正常速度行走。发生的情况是当释放冲刺按钮时,即使方向按钮仍被按住,玩家也会停止。
public function addControllerListeners(){
controller.leftButton.addEventListener(TouchEvent.TOUCH_ROLL_OVER, moveCharLeft);
controller.leftButton.addEventListener(TouchEvent.TOUCH_BEGIN, moveCharLeft);
controller.leftButton.addEventListener(TouchEvent.TOUCH_END, playerStop);
controller.leftButton.addEventListener(TouchEvent.TOUCH_OUT, playerStop);
controller.leftButton.addEventListener(TouchEvent.TOUCH_ROLL_OUT, playerStop);
sprintButton.addEventListener(TouchEvent.TOUCH_ROLL_OVER, playerSprint);
sprintButton.addEventListener(TouchEvent.TOUCH_BEGIN, playerSprint);
sprintButton.addEventListener(TouchEvent.TOUCH_END, playerStopSprint);
sprintButton.addEventListener(TouchEvent.TOUCH_OUT, playerStopSprint);
sprintButton.addEventListener(TouchEvent.TOUCH_ROLL_OUT, playerStopSprint);
}
public function playerSprint(e:Event = null) {
playerChar.sprint = true;
trace("Player Sprint");
}
public function playerStopSprint(e:Event = null) {
playerChar.sprint = false;
trace("stopSprinting");
}
public function moveCharLeft(event:TouchEvent):void{
playerChar.setWalk("left");
}
public function playerStop(event:TouchEvent):void {
var target:String = event.target.name;
if(target == "upButton" || target == "rightButton" || target == "downButton" || target == "leftButton"){
trace("Player Stopped from: " + event.target.name + " - " + event.currentTarget.name);
playerChar.direction = "idle";
}
}
停止播放器功能中的跟踪表明目标名称是按住的控制器按钮。即使被释放的按钮是冲刺按钮。
如果它有助于在舞台上添加按钮。我不认为这应该有所作为,但你永远不知道。