So, in my game I have created several platforms that randomly spawn and move upwards, the aim of the game is for the player to constantly be moving down, and avoid reaching the top, I have the left and right movement working fine, and I have a boolean called hittingPlatform which is false, and in a loop event I move the player down if hittingPlatform is equal to true.
However, when the player does hit it, I set it to true, in the loop event make him move upwards with the platform, my problem is that when he goes back off the platform, I need to set it to false. I tried using an else statement in the collision detection but that didn't work, and I don't know what else to do, any suggestions? If it doesn't make sense/isn't clear enough please do tell me!
var player:Player = new Player();
var platformOne:PlatformOne = new PlatformOne();
var platformTwo:PlatformTwo = new PlatformTwo();
var hittingPlatform:Boolean = false;
stage.addEventListener(Event.ENTER_FRAME,loopEvent);
player.addEventListener(Event.ENTER_FRAME,playerCollision);
function playerCollision(event:Event):void{
//So here I need to make it if they move off the platform set it back to false if(player.hitTestObject(platformOne)){ hittingPlatform = true; } else if(player.hitTestObject(platformTwo)){ hittingPlatform = true; } }
function loopEvent(event:Event):void{
if(!hittingPlatform){
player.y -= 5;
}
else if(hittingPlatform){
player.y += 5;
}
}
Aucun commentaire:
Enregistrer un commentaire