Implementing Toggle Switches and Barriers for a Platform Game



  • I'm new to Flixel with about a week into it. I'm really liking it but still learning how to use it.

    I'm working on a platform game and I have a toggle switch that opens a barrier. Currently I have my barrier as a FlxTilemap and the switch is a FlxGroup. When I toggle the switch, it kills or revives the barrier. My goal is to have multiple switch/barrier pairs so one switch opens one barrier. I don't think I want to use separate tilemaps for each barrier. My toggle switch is in its own class and I could pass a barrier object to it. I could make separate tilemaps for each barrier, but this doesn't seem like good way to do this.

    Does anyone have a suggestion of a better way to do this?


  • administrators

    Why not use a FlxSprite per barrier?



  • @Gama11

    I'm making multiple levels with csv files for my tilemaps and sprite coords. These barriers can be of any size and I use a tilesheet for them. They need to behave like the main platform tilemap with collisions. I want a generic way to do this so all I need to do is create my level data and they will work. I don't know how to do this using sprites.


  • administrators

    If the barriers are part of a bigger tilemap, you could just delete and add the respective tiles to toggle it. Check out setTile() (Tile == 0 removes a tile).



  • You can use setTile() method of your tilemap to change individual tile to another one from the same tileset



  • Ah, OK. That's what I was looking for. Thanks!



  • Actually, I still have a problem of associating each of the barriers set of tiles to a particular toggle switch. I can easily do it with only one switch and one barrier. I guess I was hoping that someone's done this before with a clever solution.



  • You should merge all tilesets you wish to use in the tilemap into one. It can be done externally (by hand, texturepacker, etc) or with FlxTileFrames.combineTileFrames().



  • @starry-abyss

    Thanks. I'll have a look at that, I'm not familiar with it. Right now I'm using one tilemap for the barriers and I have a multi-dimensional array of the tile indexes that I populated in my create() function. Then I have a loop to toggle them on/off. There's only a few tiles in each barrier.