How do I spawn a sprite from a tile?

Get help using Construct 2

Post » Sat Nov 26, 2016 12:55 am

How could i spawn a sprite from a tile, when (and where) this tile comes on screen?
Something like create object at X = Tilemap.SnapX(???), Y = Tilemap.SnapY(???), where ??? equals to the position of the particular tile that's going into screen -- or, say, colliding with a proximity box...
B
23
S
11
G
6
Posts: 181
Reputation: 5,003

Post » Sat Nov 26, 2016 4:29 pm

I don't think I fully understand what you are trying to do.
Do you want to spawn a Sprite at the position of a tile when that tile is added or changed?
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sat Nov 26, 2016 8:56 pm

@randomly Humm. Yeah. No. What I actually need is to create a sprite over a tile, when said tile collides with another object. The problem I'm finding is how to request the position of the tile. Or so i think!
Thanks for your answer! 8D
B
23
S
11
G
6
Posts: 181
Reputation: 5,003

Post » Sun Nov 27, 2016 12:12 am

To get the position of the tile, you can simply use the tile's expression:
Code: Select all
Tilemap.TileToPositionX(X index of tile)
Tilemap.TileToPositionY(Y index of tile)


It also works the other way around:
Code: Select all
Tilemap.PositionToTileX(x coordinate)
Tilemap.PositionToTileY(y coordinate)


It gets harder if you want to spawn the Sprite at the exact point of collision, you would have to calculate the point of collision manually.
See here for further information.

If it's possible in your project, you can also use a workaround, for example using the coordinates of the colliding object to spawn the sprite.

If you could provide further information to the context in your project, maybe we could find a workaround.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sun Nov 27, 2016 12:39 am

@randomly thanks again for your interest mate!

The problem is, i'd like to spawn a sprite every time an object collides with a particular id of tile. So it "should" be something like:
Tilemap.TileToPositionX("Self Tile X")
Tilemap.TileToPositionY("Self Tile Y"),
but of course "self tile" is nonsense. So, could i request somehow the X,Y of the tile i just collided with?

This is all an attempt, dunno yet if is gonna work, to enhance mobile performance for me game. I'm trying to replace a lot of "spawner sprites" that i have in the map (which is a big sandbox) with tiles from a tilemap, which i red it's lighter. I have this thread here where i wail and moan at long about my performance problems, there's also a link to the game in its current, mess of a state. Any opinions are most welcome, cos im quite jammed :/
B
23
S
11
G
6
Posts: 181
Reputation: 5,003

Post » Sun Nov 27, 2016 5:30 pm

Alright, this is quite a challenge, since Tilemaps don't give you the X and Y index on collision.
(Which is very unfortunate, I don't know why that doesn't exist..)

Anyways, here is a workaround:
Download .capx

Some notes concerning the .capx:
  • It's far from perfect
  • It creates multiple instances of the sprite on collision, because collisions, 8direction and tilemaps apparently don't work very well together
  • If you have any questions (might look very complicated on the first look), don't hesitate to give me a shout.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon Nov 28, 2016 5:46 pm

@randomly well thank you so very much for your effort -- it's awesomely commented n everything! I'll dig into it right now, and see how it goes. Cheers!
B
23
S
11
G
6
Posts: 181
Reputation: 5,003


Return to How do I....?

Who is online

Users browsing this forum: Apollo14, ChoosyZerk and 59 guests