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

Get help using Construct 2

Post » Tue Jun 13, 2017 1:33 pm

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.
Code: Select all
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



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.
B
10
S
1
G
1
Posts: 63
Reputation: 840

Post » Tue Jun 13, 2017 4:31 pm

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).
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Wed Jun 14, 2017 8:36 pm

Okay, I rewrote the code and it seems to be working now.

Thanks for the pointer.
B
10
S
1
G
1
Posts: 63
Reputation: 840

Post » Thu Jun 15, 2017 3:56 pm

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.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Thu Jun 15, 2017 5:58 pm

I'm not even new, but I act like it(Alot more then I like to admit).
You should see my events, its horrendous.
B
10
S
1
G
1
Posts: 63
Reputation: 840


Return to How do I....?

Who is online

Users browsing this forum: DharmaOne and 22 guests