所以,让我在这里说清楚,我并不是想要拖东西,这就是我可以找到的东西,在点击某些东西时保持激活的东西。我想知道如何在点击它的同时移动一些东西,我已经制作了一个你使用鼠标的版本,但是我正在使用鼠标,我是否需要使用除鼠标功能以外的任何东西?
代码:
mright.alpha = 0;
mleft.alpha = 0;
stage.addEventListener(Event.ENTER_FRAME, move);
function move(e:Event)
{
if(player.y >= 33 && player.y <= 763)
{
mright.addEventListener(MouseEvent.MOUSE_DOWN, mrgh);
function mrgh(e:MouseEvent)
{
player.y -= 1;
}
mleft.addEventListener(MouseEvent.MOUSE_DOWN, mlft);
function mlft(e:MouseEvent)
{
player.y += 1;
}
}
else if(player.y < 33)
{
player.y = 33;
}
else if(player.y >= 763)
{
player.y = 763;
}
}
答案 0 :(得分:0)
试试这个:
AS3代码:
var timer:Timer = new Timer(10)
timer.addEventListener(TimerEvent.TIMER, timer_on_Timer)
function timer_on_Timer(e:TimerEvent){
move_player()
}
timer.start()
var btn_left_pressed = false
var btn_right_pressed = false
btn_left.addEventListener(MouseEvent.MOUSE_DOWN, btn_left_on_Press)
btn_left.addEventListener(MouseEvent.MOUSE_UP, btn_left_on_Release)
function btn_left_on_Press(e:MouseEvent){
btn_left_pressed = true
btn_right_pressed = false
}
function btn_left_on_Release(e:MouseEvent){
btn_left_pressed = false
}
btn_right.addEventListener(MouseEvent.MOUSE_DOWN, btn_right_on_Press)
btn_right.addEventListener(MouseEvent.MOUSE_UP, btn_right_on_Release)
function btn_right_on_Press(e:MouseEvent){
btn_right_pressed = true
btn_left_pressed = false
}
function btn_right_on_Release(e:MouseEvent){
btn_right_pressed = false
}
function move_player(){
if(player.y >= 33 && player.y <= 763){
if(btn_right_pressed){
player.y -= 1
} else if(btn_left_pressed){
player.y += 1
}
} else if(player.y < 33) {
player.y = 33
} else if(player.y >= 763) {
player.y = 763
}
}
这当然是一个非常简单的代码,但您可以添加许多内容,例如开始和停止 计时器,...