Author Topic: frustrating overlap problem  (Read 897 times)

omit

  • New Member
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
frustrating overlap problem
« on: Thu, Mar 17, 2011 »
I am having a hard time with my overlap. I almost tried everything to get it working. You can only pass the door when you have picked up the key(named trophy). That works... when you pick up a trophy the door(exit) property solid becomes false. That is exactly what i want first to happen.

But the problem is, when i pass by the door, i want it to disappear from the state, with the useTrophy function(). Something goes wrong but cant figure out what..

My FlxState class:

Code: [Select]

public var background:FlxSprite;
        public var _player:PlayerMiniState;
        public var _map:FlxTilemap;
public var ladders:FlxTilemap = new FlxTilemap;
public static var exit:FlxSprite
//public static var door:Door;
//public static var doors:FlxGroup;
public static var trophies:FlxGroup;
public static var trophy:Trophy;

override public function create():void
{
//the exit door
exit = new FlxSprite(550,1585);
exit.loadGraphic(ImgDeur,false,false);
exit.exists = true;
//exit.solid = false;
exit.fixed = true;
exit.width = 96;
add(exit);

                        //can open the exit door with it
trophies = new FlxGroup;
trophy = new Trophy;
trophies.add(trophy.createTrophy(300, 1512));
add(trophies);
}

 override public function update():void
        {
            super.update();
            _map.collide(_player);
_map.collide(lyrBlock);
_player.collide(lyrBlock);
_player.collide(exit);
FlxU.overlap(trophies, _player, Trophy.holdTrophy);
FlxU.overlap(exit, _player, Trophy.useTrophy);

}

The Trophy class:
Code: [Select]

public class Trophy extends FlxSprite
{
[Embed(source="../../../../org/flixel/data_omit/solid/trophy.png")] public static var ImgBlok:Class;

public function Trophy()
{

}

public function createTrophy(X:Number, Y:Number):FlxSprite
{
return new FlxSprite(X, Y).loadGraphic(ImgBlok, false, false);
}

public static function useTrophy(action:FlxSprite, Player:FlxSprite):void
{
//KerkState.exit.kill();
KerkState.exit.exists = false;
//KerkState.exit.solid = false;
}
public static function holdTrophy(action:FlxSprite, Player:FlxSprite):void
{
KerkState.exit.exists = true;
KerkState.exit.solid = false;
action.kill();
}
}
}

ChainedLupine

  • Member
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
    • Dit Dah Games
Re: frustrating overlap problem
« Reply #1 on: Thu, Mar 17, 2011 »
Why not use kill() on the door?

That sets the appropriate values:

exists = false (removes it from the render/update chain)
dead = true (does some additional logic inside of Flixel for ignoring the object)

If exists = false and dead != true, then the door will still be counted by some of the Flixel code as being around.