I am building a simple platformer using Flixel, beginning with the source code from Flixel creator's EZPlatformer . I would like to adjust the level's tilemap when the player sprite enters/overlaps with a sprite representing a door. I use Flixel's built in function to track if the player overlaps the door sprite.
exits
is a class level variable: public var exits:FlxGroup;
I call this function in the Update event to check for overlap:
FlxG.overlap(exits,player,UpdateScreen);
I successfully catch when they overlap, however when I try and load the new tilemap, the old one continues to show. I use this function to attempt to update the tilemap on the screen:
public function ChangeScreen():void
{
//load the screen and locations of sprites(e.g. player, exits) based on current screen
switch(currentScreen)
{
case 1:
//load tilemap
level = new FlxTilemap();
level.loadMap(FlxTilemap.arrayToCSV(data1,40),FlxTilemap.ImgAuto,0,0,FlxTilemap.AUTO);
add(level);
break;
case 2:
//load new tilemap
level = new FlxTilemap();
level.loadMap(FlxTilemap.arrayToCSV(data2,40),FlxTilemap.ImgAuto,0,0,FlxTilemap.AUTO);
add(level);
break;
}
}
I thought that I would need to first call remove
on level
to take it off the stage, and then call add
on it, however, when I do that, the tilemap does not show up at all. What is the correct way to do this?