雪碧击中一个看不见的平台

Sprite hitting an invisible platform

您好,我目前正在制作一款平台游戏,但我遇到了精灵从舞台最底部开始的问题: 像这样:

如果我尝试跳跃,它会停留在一个看不见的平台上:

到目前为止,这是我的外部代码:

import flash.display.*;
import flash.events.*;
import flash.ui.*;

public class codes extends MovieClip
{
    public function codes(){
        chara.stop();
        stage.addEventListener (KeyboardEvent.KEY_DOWN, keydown);
        stage.addEventListener (KeyboardEvent.KEY_UP, keyup);
        stage.addEventListener (Event.ENTER_FRAME, gameloop);
    }
    var mspeed:Number=0;
    var sy:Number=2;
    var gv:Number=1;
    var jumped:Boolean=false; 

    function keydown (e:KeyboardEvent){
        if (e.keyCode==Keyboard.LEFT){
            mspeed=-10;
            chara.gotoAndStop(2);
        }
        if (e.keyCode==Keyboard.RIGHT){
            mspeed=10;
            chara.gotoAndStop(1);
        }
        if (e.keyCode==Keyboard.SPACE) {
            if (!jumped){
                sy=-20;
                jumped=true;
            }
        }
    }

    function keyup (e:KeyboardEvent){
        if (e.keyCode==Keyboard.LEFT){
            mspeed=-0;
        }
        if (e.keyCode==Keyboard.RIGHT){
            mspeed=0;
        }
    }

    function gameloop (e:Event) {
        chara.x += mspeed;

        if (chara.x<0) {
            chara.x=0;
        }
        if (chara.x>950) {
            chara.x=950;
        }

        sy+=gv;
        if (!jump.hitTestPoint(chara.x,chara.y,true)) {
            chara.y+=sy;
        }

        for (var i=0;i<10;i++) {
            if (jump.hitTestPoint (chara.x, chara.y, true)) {
                chara.y--;
                sy=0;
                jumped=false;
            }
        }
    }

 }

It looks like he is standing on the platform with his face! Are you sure that's not what's happening?


It's not bug. It's doing what you told it to. It may be as simple as making sure that the character has his feet at the origin point of the movie clip (the little white dot when you edit the movie clip)