문제

I am creating flash android game with as3. I already made object jumping on platforms, but I am facing problems with following object vertically. Any help or suggestion how to improve code are more than welcome!

The object instance name is hero and all platforms are made as one movie clip whose instance name is level

Here is my code:

import flash.events.Event;

var Key:KeyObject = new KeyObject(stage);
var dy:Number=10;
var gravity:Number=1;    
var canjump:Boolean = false;

stage.addEventListener(Event.ENTER_FRAME,onenter);

function onenter(e:Event) :void {

    if (Key.isDown(Key.LEFT)) {
    hero.x-=30;
    hero.y-=10;
    }

    if (Key.isDown(Key.RIGHT)) {
    hero.x+=30;
    hero.y-=20;
    }


    dy+=gravity;

    if (! level.hitTestPoint(hero.x,hero.y,true)) {   //if the hero not hitting the platform
        hero.y+=dy;
    }
    if (dy>10) {   //controls gravity
        dy=10;
    }
    for (var i:int = 0; i<10; i++) {
        if (level.hitTestPoint (hero.x,hero.y,true)) {   
            hero.y--;
            dy=0;
            canjump=false;
        }
    }

}
도움이 되었습니까?

해결책

I'm not quite sure whether it would work on android but on my code for some other platformer, I used the script

this.y=-hero.y+(stage.stageWidth/2); 

this follows the character as he ascends, in the swf file at least; hope it helps!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top