我想要製作一個移動跳躍的遊戲,但是我選擇關卡後都不能直接移動,而是需要點擊一次畫面才可以正常執行,請問該如何解決呢?
也請問要怎麼讓物件不會超過一個形狀外(類似牆壁的概念)以及平台如何接住物件(就是讓物件可以站在平台上面)
語法如下:
const KEY_UP: uint = 38;
const KEY_DOWN: uint = 40;
const KEY_LEFT: uint = 39;
const KEY_RIGHT: uint = 37;
//------------------------
var speed: Number = 3;
//------------------------
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler_2);
function fl_KeyboardDownHandler_2(event: KeyboardEvent): void {
var code:uint = event.keyCode;
if (code == KEY_LEFT) {
box_mc.x += speed;
new Rectangle(mc_frame.x, mc_frame.y, mc_frame.width - box_mc.width, mc_frame.height - box_mc.height)
};
if (code == KEY_RIGHT) {
box_mc.x -= speed;
};
//if (code == KEY_UP) {
};
}