Sprite positioning when canvas loads

I’m having a hard time making heads or tails of this.

I know that sprite x/y positions are relative to the sprite’s top-left corner (I’ve suggested that they be changed to the sprite’s center but that’s another conversation…).

What I don’t understand is that when I position a canvas so that it’s top-left corner (0,0) touches a button’s bottom-right corner and then – with only the blocks below added to the sprite – I preview the project, the sprite re-sizes itself and moves and ends up in a place that definitely isn’t x=0, y=0.

This video shows what happens when I press the preview button:

Ignore the three game pieces above the button & canvas area.

canvas bug

Canvas:

image

Blocks:

image

Completed Preview:

image

1 Like

Or how about this one… both sprites are 50 width & height.

Blocks:

Preview #1:

image

Preview #2:

image

???

Project Link

https://x.thunkable.com/copy/e21ce477cdc205dcc9ecb63462ca4293

Sprites use the midpoint for coords. If you try to put them half off the canvas, strange things happen.

1 Like

I tested the project @tatiang sent and set the x and y to 25 as mid-point and it behaved as expected. I set the other sprite to 50 and it also showed expected outcome.

image

image

2 Likes

That’s good to know!

@muneer thanks for confirming that. I actually did find the same to be true. My sprites still resize and move which is weird but at least they end up in the right spots using your values:

image

1 Like

Do your sprites resize or does your canvas? I’ve seen the canvas/stage do a resize, but not sure I’ve seen sprites do it.

1 Like

I’m not sure. If you notice the gif in my first post, that’s what I’m referring to.

It happens even in the Design tab without previewing and it happens with a brand new project if I just drop a canvas component onto a screen.

I’m working on a snap-to-grid demo and it works well but if I give the sprite any momentum when dropping it, it glides to a new position that is no longer snapped to the grid.

Does anyone know how to prevent that? I basically want to disable movement for the sprites. They should be draggable but not moveable if that makes sense.

https://x.thunkable.com/projects/60bcf3db90b63a00128256d1/5bfb81a8-0cff-4cf3-9558-01010c4cdfd6/designer

drag demo

1 Like

That’s your canvas resizing - if you put a border on it, you can see it. It’s not really a sprites problem.

1 Like

Try this:

(Do both sprites this way.)

1 Like

How do you do that? I’m using the drag-and-drop interface and the only thing I see is “frame color.” When I set that, it seems like it might show up in the Design tab but when I preview it, the stage doesn’t have a border.

Sorry, I meant frame. :slight_smile:

Good idea but the sprites still move. Less/slower but there’s still movement rather than snapping to a position.

Ah. When I tested on web, it worked.