How do I spawn a sprite from a tile?

1 favourites
  • 7 posts
From the Asset Store
Piano tiles
$9.99 USD
Template for a piano tiles game, fully documented in comments and video
  • 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...

  • 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?

  • 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

  • To get the position of the tile, you can simply use the tile's expression:

    Tilemap.TileToPositionX(X index of tile)
    Tilemap.TileToPositionY(Y index of tile)[/code:dyk8a1uo]
    
    It also works the other way around:
    [code:dyk8a1uo]Tilemap.PositionToTileX(x coordinate)
    Tilemap.PositionToTileY(y coordinate)[/code:dyk8a1uo]
    
    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 [url=https://www.scirra.com/forum/how-do-i-retrieve-collision-point-coordinate_t121791]here[/url] 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.
  • 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 :/

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.
  • 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!

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