문제는 시간이 지남에 (그리고 모든 번) 선수의 위치를 증가 할 필요가있다 :
여기 내 이동 코드입니다.
트위닝 엔진 (tweenlite와 같은)을 사용하거나 자신의 타이머를 굴리거나 프레임 처리기를 입력 할 수 있습니다.
if (e.keyCode == 38) //up
{
if(!isJumping){
isJumping = true;
velocity = 50; //how much to move every increment, reset every jump to default value
direction = -1; //start by going upwards
this.addEventListener(Event.ENTER_FRAME,jumpLoop);
}
}
var isJumping:Boolean = false;
var friction:Number = .85; //how fast to slow down/speed up - the lower the number the quicker (must be less than 1, and more than 0 to work properly)
var velocity:Number;
var direction:int = -1;
function jumpLoop(){ //this is running every frame while jumping
fireboy1.y += velocity * direction; //take the current velocity, and apply it in the current direction
if(direction < 0){
velocity *= friction; //reduce velocity as player ascends
}else{
velocity *= 1 + (1 - friction); //increase velocity now that player is falling
}
if(velocity < 1) direction = 1; //if player is moving less than 1 pixel now, change direction
if(fireboy1.y > stage.stageHeight - fireboy1.height){ //stage.stageheight being wherever your floor is
fireboy1.y = stage.stageHeight - fireboy1.height; //put player on the floor exactly
//jump is over, stop the jumpLoop
this.removeEventListener(Event.ENTER_FRAME,jumpLoop);
isJumping = false;
}
}
이 더 명확 해주십시오 : 여기
은 후자의 예이다. "문제"는 귀하의 질문을 읽는 사람에게 아무런 의미가 없습니다. 내 생각 엔 업 키가 풀릴 때까지 움직이기를 원한다고 생각하는거야? 어떤 경우에는 키 다운 이벤트와 키 업 이벤트 사이에서 프레임 입력 핸들러 또는 타이머를 실행하면됩니다 (실제로 해당 이벤트가있는 경우 예제를 보여줍니다) – BadFeelingAboutThis
죄송합니다. 내 질문은 지금. 위쪽 화살표 키를 한 번 누르면 특정 높이로 떨어지면서 넘어지기를 원합니다. –