플랫폼 게임을 만들려고하고 있으며 실행, 점프 및 이중 점프 기능이 있습니다. 이제는 내 문제는 플레이어가 점프 버튼을 누르고 영웅이 한 번만 점프하는 대신 계속 점프하는 것입니다. 내가 위로 버튼을 누르고 있으면 나는 그것을 원하지 않는 점프를 계속할 것이다. 나는 단지 키가 여전히 눌러져 있어도 한번 점프를 수행하기를 원한다. 나는 이중 점프에 대해 같은 것을 원한다. 어떻게 할 수 있을까?AS3 : 단일 키만 누르기
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class Player extends MovieClip
{
//Player run speed setting
var RunSpeed:Number = 8;
//Player key presses
var RightKeyPress:Boolean = false;
var LeftKeyPress:Boolean = false;
var UpKeyPress:Boolean = false;
//Jump variables
var Gravity:Number = 1.5;
var JumpPower:Number = 0;
var CanJump:Boolean = false;
var DoubleJump:Boolean = false;
public function Player()
{
// constructor code
stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyPressed);
addEventListener(Event.ENTER_FRAME,Update);
stage.addEventListener(KeyboardEvent.KEY_UP,KeyReleased);
}
function KeyPressed(event:KeyboardEvent)
{
//When Key is Down
if (event.keyCode == 39)
{
RightKeyPress = true;
}
if (event.keyCode == 37)
{
LeftKeyPress = true;
}
if (event.keyCode == 38)
{
UpKeyPress = true
}
}
function Update(event:Event)
{
//Adding gravity to the game world
JumpPower += Gravity;
//if player is more than 300 on the y-axis
if (this.y > 300)
{
//Player stays on the ground and can jump
JumpPower = 0;
CanJump = true;
DoubleJump = false;
}
//If player is on floor and right key is pressed then run right
if ((RightKeyPress && CanJump))
{
x += RunSpeed;
gotoAndStop('Run');
scaleX = 1;
}
else if ((LeftKeyPress && CanJump))
{
//Otherwise if on floor and left key is pressed run left
x -= RunSpeed;
gotoAndStop('Run');
scaleX = -1;
}
else if ((UpKeyPress && CanJump))
{
//Otherwise if on floor and up key is pressed then jump
JumpPower = -15;
CanJump = false;
gotoAndStop('Jump');
DoubleJump = true;
}
//If on floor and right and up key are pressed then jump
if ((RightKeyPress && UpKeyPress && CanJump))
{
JumpPower = -15;
CanJump = false;
gotoAndStop('Jump');
DoubleJump = true;
}
//If on floor and left and up key are pressed then jump
if ((LeftKeyPress && UpKeyPress && CanJump))
{
JumpPower = -15;
CanJump = false;
gotoAndStop('Jump');
DoubleJump = true;
}
//If jumped and right key is pressed then move right
if ((RightKeyPress && CanJump == false))
{
x += RunSpeed;
scaleX = 1;
}
else if ((LeftKeyPress && CanJump == false))
{
//Otherwise if jumped and left key is pressed then move left
x -= RunSpeed;
scaleX = -1;
}
//If in air and able to doublejump and pressed up key, then double jump
if (UpKeyPress && DoubleJump && JumpPower > -2)
{
JumpPower = -13;
DoubleJump = false;
gotoAndStop('DoubleJump');
}
//If on floor and no key is presses stay idle
if ((!RightKeyPress && !LeftKeyPress && CanJump))
{
gotoAndStop('Idle');
}
this.y += JumpPower;
}
function KeyReleased(event:KeyboardEvent)
{
if (event.keyCode == 39)
{
event.keyCode = 0;
RightKeyPress = false;
}
if (event.keyCode == 37)
{
event.keyCode = 0;
LeftKeyPress = false;
}
if (event.keyCode == 38)
{
event.keyCode = 0;
UpKeyPress = false;
}
}
}
}
이중 점프가 발생하는 곳에 중단 점을 넣으려고 했습니까? 부울을 가진 논리가 올바르게 작동해야하는 것처럼 나에게 보인다. 그러나 당신은 어떤 이유로 그 블록에서 반복적으로 끝나야 만 하는가? 업데이트 기능의 주요 지점에서 부울을 추적 해보십시오. – shaunhusain
@shaunhusain : 중단 점? 나는 AS3에 익숙하지 않기 때문에 아직 많이 알지 못하지만 빨리 배우고 있습니다. – user2350724
문제가되지 않습니다.이 링크를 확인하십시오. http://www.adobe.com/devnet/flash/articles/flash_as3_debugging.html 또는 조금만 Google을 사용하면이 기사의 후반부가 도움이 될 것 같지만 길기는합니다. – shaunhusain