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
70
S
13
G
2
Posts: 989
Reputation: 6,914

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
85
S
27
G
84
Posts: 5,059
Reputation: 57,352

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
58
S
23
G
22
Posts: 890
Reputation: 16,790

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
70
S
13
G
2
Posts: 989
Reputation: 6,914

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
70
S
13
G
2
Posts: 989
Reputation: 6,914

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
58
S
23
G
22
Posts: 890
Reputation: 16,790

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
70
S
13
G
2
Posts: 989
Reputation: 6,914

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
26
S
15
G
23
Posts: 2,045
Reputation: 17,081

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: Cryttexx, Greaver, luckyrawatlucky, QuantumMMX, SnipG and 13 guests