Stencyl 3.4.0 is now out. Get it now!

Trying to make a game like snake and can't work something out...

SomeT

  • *
  • Posts: 143
I got the thing moving, but can't make it move to the grid / locked to the grid at 32 x 32 so it always moves diagonally say if I push up and left in quick succession, how do I lock it to the grid of 32x32 on each movement / key press of say up or down etc...

JeffreyDriver

  • Posts: 1119
The 'slide' block will let you move to grid. To stop diagonal movement I suppose that you'd need to queue the next command so that it only runs once the current movement has finished.

SomeT

  • *
  • Posts: 143
I tried this but could not get it to work: https://pasteboard.co/GBozI0d.png

« Last Edit: July 17, 2017, 12:34:15 pm by SomeT »

squeeb

  • Posts: 1079
I wouldn't place it in an updating block.  It's trying to slide it there over 1 second.. a bunch of times per second.. Try a created block and do every 1 second ?

SomeT

  • *
  • Posts: 143
I don't get what you mean?

JeffreyDriver

  • Posts: 1119
Anything in an 'always' event is run 100 times per second, unless there's something (like a boolean) to stop it, so in your example it's being slid by X 32px, Y 32px repeatedly.

See the attached example of a snap-to-grid behaviour I made. It moves the actor by 16px and prevents it being moved again until it's finished sliding.

SomeT

  • *
  • Posts: 143
Is there not a shorter way of doing this? It seems a bit overly complex just to make it align to the grid?

JeffreyDriver

  • Posts: 1119
The snap-to-grid code itself isn't that complicated. The most complex bit is the code that checks for tiles and prevents the actor. If you don't need to check for tiles you can drop those bits.

Also, I have some booleans in there at the top which you won't need.