dimanche 9 avril 2017

Sprite hitting an invisible platform

Hi there Im currently making a platform game and I'm having trouble where the sprite starts at the very bottom of the stage: Like this and if I try to jump, it stays on an invisible platform: Like this

Here's my external code so far :

package  
{
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;
    }
}

}





 }
 }

Aucun commentaire:

Enregistrer un commentaire