How do I spawn an object on a tilemap tile?

Get help using Construct 2

Post » Fri Jan 29, 2016 6:14 pm

I read the tutorials about the tilemap but I didn't find how to spawn a sprite in the tilemap tile that was touched.

I didn't find also any option in the tilemap actions. Is not possible?

Thanks in advance.
B
72
S
13
G
2
Posts: 989
Reputation: 6,969

Post » Fri Jan 29, 2016 7:22 pm

You can do it with the tilemap expressions. First you use the expressions to convert the touch.x and y to the tile column and row. Next you use another one of the expressions to to convert the row and column to the xy of a tile.
B
88
S
30
G
89
Posts: 5,112
Reputation: 60,335

Post » Fri Jan 29, 2016 7:55 pm

There are also expressions that combines both so the final expression doesn't become monstrous.

On Touch -> Create object at x = Tilemap.SnapX(Touch.X), y = Tilemap.SnapY(Touch.Y)
B
59
S
24
G
23
Posts: 934
Reputation: 17,503

Post » Fri Jan 29, 2016 8:18 pm

Hi @R0J0hound

I did something similar (or equal) that you suggested, but it doesn't have accuracy.

https://www.dropbox.com/s/zvb471nqpoam6 ... .capx?dl=0
Last edited by RBuster on Fri Jan 29, 2016 8:45 pm, edited 2 times in total.
B
72
S
13
G
2
Posts: 989
Reputation: 6,969

Post » Fri Jan 29, 2016 8:24 pm

Thanks, @Magistross

Nice and simple solution, but I'm having the same problem: no accuracy. I'm creating objects out of the tile that I clicked. I need to create it inside the tile. How can I fix it? Thanks in advance.
Last edited by RBuster on Fri Jan 29, 2016 8:50 pm, edited 1 time in total.
B
72
S
13
G
2
Posts: 989
Reputation: 6,969

Post » Fri Jan 29, 2016 8:49 pm

SnapX/Y and TileToPositionX/Y return the position in the middle of a particular tile. Depending on where your sprite origin is, you might have to shift the position a bit. e.g. Tilemap.SnapX(Touch.X) - 16
B
59
S
24
G
23
Posts: 934
Reputation: 17,503

Post » Fri Jan 29, 2016 8:55 pm

Ok, Thanks.

Is possible to check if any tile is overlapping another sprite that I inserted after the game starts (not during the game)?
B
72
S
13
G
2
Posts: 989
Reputation: 6,969

Post » Sat Jul 09, 2016 9:52 pm

can someone explain how this works to me plz ?
having a hard time with tile x,y expressions.
I need to understand it a little so i can use it.

Right now im trying to spawn a sprite on top of tiles #27 and #28.
Right now i have 0 clue on how to do that.

tile #27 is x-210 y-49
tile#28 is x-238 y-49

example i wanna spawn sprite at the start. wherever tile #27 is from tilemap
B
8
S
3
G
3
Posts: 39
Reputation: 2,560

Post » Sun Jul 10, 2016 4:28 pm

B
28
S
16
G
23
Posts: 2,115
Reputation: 17,371

Post » Sun Jul 10, 2016 5:24 pm




thats wierd. Cant open it. says its on release 227. but thats the same release i got.
B
8
S
3
G
3
Posts: 39
Reputation: 2,560

Next

Return to How do I....?

Who is online

Users browsing this forum: Benjo11, dzert14, imhotep22, mdvgames, yodashii and 2 guests