In my gave there is a chance that i have multiple worlds, so far i have just one, and i have on player in my game and i have to check for collisions with multiple objects, i started testing collisions in the world update function but then i found that i’m gonna have to do that for every object, i tried testing collisions in the update method in every object just like this :
Example Object :
override public function added():void
{
initWorld();
super.added();
}
private function initWorld():void {
_cave = this.world as CavernWorld;
_player = _cave.player; // i get the player reference from the world
}
override public function update():void
{
if (Globals.playerAlive == true) {
var bonus:Entity = _player.collide("speedBonus", _player.x, _player.y);
if (bonus != null) {
trace('player hit bonus');
Globals.playerVelocityX = 100;
}
}
super.update();
}
My World :
override public function update():void
{
var level:Entity = _player.collide("level", _player.x, _player.y);
if (level != null) {
Globals.playerAlive = false;
trace("lost from level");
FP.world.active = false;
}
var stala:Entity = _player.collide("stala", _player.x, _player.y);
if (stala != null) {
trace("lost stala");
FP.world.active = false;
}
}
I’m wondering what’s the best way to check for collisions in case i have several objects and possibly multiple worlds as well .