0 Favourites

Tilemap find a region of tiles and replace it with a sprite.

  • I'm making my game use only tilemaps then store the tilemap data into an XML file, which the game reads.

    At the moment I have done it so it reads it from the XML.

    Once it loaded it need to convert certain tiles into objects.

    But when I've tried it seems to not work. I'm currently at college and can't provide cape but I will when I get home but out of memory it's something like this.

    For Loop "y" in range 0,(Tilemap.Width/16)
         For Loop "x" in range 0,(Tilemap.Width/16)
         tilemap.TileAt(x,y) == 8 then
         tilemap:removeTile(x,y)
         createObject("lava",x*16,y*16)
          For Loop "xx" in range loopindex("x"),(Tilemap.Width/16)-loopindex("x")
               tilemap.TileAt(xx,y) == 8 then
               tilemap:removeTile(x,y)
               lava.width += 16
               else breakloop[/code:1defa2zy] 
    
     
    What happens: Code works as expected however it creates multiple lava sprites on the same width 
     
    I'm guessing the loop runs side by side so it calls the function on multiple tiles.
    (using shader to make sprite work like tiled background, and this isn't the problem)
     
    I'm also sorry if this makes little to no sense.
  • Do you have the loop as a root event? Remember that all root events are on a perpetual loop, so if you don't want your capx producing an infinite number of sprites, then you need to condition it on something that only happens once (like "On Start of Layout" for example).

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Okay, I rewrote the code and it seems to be working now.

    Thanks for the pointer.

  • Everyone who is new to c2 makes that same mistake sometime.

    I accidentally produced around 1,000,000 sprites before I shut off my browser, lol.

  • I'm not even new, but I act like it(Alot more then I like to admit).

    You should see my events, its horrendous.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)