Sprite Grid movement

I am trying to figure out how the ‘Sprite Grid’ extension works. I see that I can move a sprite by using the controller buttons. Is there a way to set the speed? Also, what does the block 'snap sprite to grid and stop [true/false] do?

I was thinking about using this extension to move over land. However, when I move onto a another sprite that is moving, I need to use x,y positions. Is there any way to turn of the block ‘grid move sprite with buttons’?

This is a hypothesis: I think that the snap means like just changing their x, y positions in a “snap” instead of a smooth transition. I don’t know who made the extension, but it would be a good idea to find out who made it

Ah, @darzu made that one (I think)

1 Like

“snap to grid” finds the closest grid location and “snaps” the sprite to the center of that location. Also, after using “snap” the sprite is then part of the “grid” and will be returned by the “array of sprites in X” blocks. If I sprite isn’t snapped to the grid or placed with the grid blocks, the grid system will consider it outside the grid and it won’t be returned by “array of …” blocks . The “stop” flag will set velocity and acceleration to zero if they’re present.

There isn’t a way to disable move with buttons, that should definitely be added. Created a new issue:

Right now grid movement speed is one grid per press. What kind of speed control would you like?
One thing I’ve been meaning to add is smooth transitions:


Thanks for getting back to me on this question. I am building a remake of Frogger. When the player is on land, I get the tile location next to player, place a sprite on it (lets call it ‘marker’), and have the player move to it. There is an issue where the sprite does not completely make it to the sprites location (Bug found when a sprite follows a sprite), so I was thinking about using your grid extension. My work around is to check when the vx/vy is zero, to indicate that the sprite is no longer moving so that it can move again.

That is why I was curious if it were possible to set the speed (when snapping) so that it looks like the players moves. My other question about turning off the ‘move by grid’ option, is when the player moves over water and lands on a log/turtle. I want the player to then move by x/y coordinates. In fact, I have stopped using the tile location to move the player all together, as I can just have it move 16px each time. This will work better when the player jumps off a log and back onto land.

@jwunderl & @darzu
May I ask another question regarding velocity/acceleration?
I guess when a sprite is set to ‘start following’ another sprite, that it first accelerates until it reaches the desired velocity and starts to decelerate as it nears the target. When the player has stopped moving, I check whether it overlaps a log and set the player’s vx to that of the log. Is this correct, or do I need to set a value for acceleration?
After setting the vx, the player does not move with the log. I’m starting to suspect that maybe the player does not move, because it is still set to follow the other sprite. I might try setting the vx of the ‘marker’ sprite as well to see if that works.

This leads me inexorably to asking another question… If a sprite is set to follow another sprite, should there not be a way to stop that behavior? Or does this happen automatically?

I love your YouTube films; they are informative, easy to follow and fun to watch. Do you still have ‘the beard’? :grin:

I see that you are also busy on YouTube with Richard and Vivian making games; they are always fun to watch. :ok_hand:

1 Like

My suspicions were correct. Since the player is set to follow the ‘marker’ sprite, I also needed to change the vx of the marker as well. It works like a charm.

In my case I don’t need to turn off the option of following the marker sprite, but I might be a nice feature. Similar to pac-man, one it eats a ‘power pill’, you might want the ghosts to stop following the player.

You can make a sprite stop following by passing 0 as the speed (or null for the sprite to follow, but that’s harder in blocks as there’s no explicit null block yet).

We keep a bit of momentum when the sprite is following so it ‘feels’ right / doesn’t just snap to max speed at the given angle; this is configurable with the optional third parameter in javascript, but isn’t included on the block. We don’t decelerate as you get close to the target though (except completely, when you are on top of the sprite you are following).

1 Like

Good to know, thanks.

This is a great use case for turning off grid movement, thanks! Unfortunately I think the only work around right now is to not use ‘move by grid’ at all and code your own grid movement on the direction keys that you can fully control. Hopefully that block will be added soon.

RE YouTube films: thanks! If you have any topic suggestions, I’m keeping a list and would love to hear ideas. And yeah, I still have a beard :slight_smile:

1 Like

Thanks for your advice. I have indeed coded my own movement by keeping track if the player has moved, and can only move again once it has stopped. I works fine.

Alright I added a way to stop the “grid move with buttons” in version extension version 1.2.2.

just pass null / empty to the “move with buttons”.


Your extension is great. I use it also for placing sprites at various row/column locations, and it was invaluable at finding the location of a sprite within the tile map. Thank you.

1 Like

If you haven’t seen it yet, the “Tilemaps” extension (https://github.com/microsoft/pxt-tilemaps) also has blocks for getting and placing sprites at row/col locations, plus a bunch of other helpful blocks.

I do use that extension as well, it is very helpful. The colour-coded tilemap is also great.

1 Like