Spawning objects on a grid?

0 favourites
  • 4 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Hello,

    here is my first novice question/problem that I dont know how to tackle properly/simply.

    I have a character with top down smooth movement. The background is made of lets say 16x16 tiles. I want to spawn objects (with character) always on the centre of the tile character is standing on. If he is on the x1, y1 - object spawns at (8,8). If he comes to (16,16) his spawned object appears at (8,8). If he comes to (17,17), object spawns at (24, 8) and so forth. I hope I described the idea correctly.

    THX on any help!


  • To snap an X Y position the basic idea is



    so for a 16x16 grid it's



    But depending on your objects origins you may need to add an offset

    or instead of round use Floor or Ceil

    In your example lets say "character" and "spawn_object" both have centered origin points. It's a 16x16 grid and you want it placed in the center of the tile. you would put an action like this.

    system create "spawn_object"



    hope that helps.

    [edit]: I should mention I'm using "system create object" instead of having the "character" spawn the object. That way It can be done in one action with an expression instead of spawning the object then snapping it's position with a second action. Also when one object spawns another the spawned object inherits it's rotation. Your example didn't mention wanting that.

  • Onzephyr: Thanks!!! Very simple and elegant. yea, learning the native expressions.

    bye bye

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • is there a way to do this in construct 2?

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