I am trying to create a platformer game and i am trying to make "player1" stop when it hits a "platform". here is my code so far,
gotoAndStop("gameStart");
import flash.display.MovieClip;
import flash.events.*;
import flash.ui.Keyboard;
import flash.ui.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
player1.gotoAndStop("nothing");
//private var speed:Number = 0;
//private var maxspeed:Number = 4;
var myTimer:Timer = new Timer(10,0);
stage.focus = this;
player1.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
/*
myTimer.addEventListener(TimerEvent.TIMER,someFunction);
myTimer.start();
function someFunction(event:TimerEvent) {
player1.y += 2;
}
*/
function setup() {
stage.addEventListener(KeyboardEvent.KEY_DOWN, reactToArrowKeys);
}
setup();
function reactToArrowKeys(keyEvent:KeyboardEvent) {
if (keyEvent.keyCode == 37) {
if (player1.x > 0) {
player1.x -= 5;
}
} else if (keyEvent.keyCode == 39) {
if (player1.x < 700) {
player1.x += 5;
}
}
}
function enterFrameHandler(e:Event):void {
if (player1.hitTestObject(platform)) {
trace("hitting");
} else {
player1.y += 4;
}
}
however the hitTestObject function (enterFrameHandler) does not work properly and will always take the "else" route.
please help!