0 votes

I'm using a sprite sheet to animate a character, using the Sprite node and the Vframes, Hframes properties.

It seems to work well, but the sprite physically moves (changes its position) during the animation, and that's not good because the sprite will also move during the game (the sprite will be at a slightly different position to the kinematicbody2d parent node).

(It should always be in the center)

For reference this is the image that I'm using for the spritesheet (996 x 239). Can anyone help?

in Engine by (90 points)

1 Answer

+1 vote
Best answer


its all about that texture.

996(px) ÷ 9 (frames) = 110.66 px (lets say 110 px for simplicity)

If i add line every 110 px (so frame every 110, 220, 330, 440, 550, 660, 770, 880, 990), you can clearly see whats wrong (dont mind last line cutting his face, thats that .66 px × 9 frames we ignored)

Maybe author of that spritesheet want it to look like walking without moving sprite (thats what you got :) ), idk. Dont think there is any technique to "multiplying offset every frame" and who know if that offset is distributed equally, i would scratch this idea.)

You have to pack that texture "more tightly" (draw lines as i did, resize texture to width ÷ frames = whole integer, but add at least two transparent pixels between sprites and one on every side of image*) or split it to multiple images and use AnimatedSprite.

Edit: or, you can use "region" and animate "region rectangle" property of your sprite (but i think repacking texture is little bit easier)

Edit2: *: so you will have padding and margin. Its becouse coord on textures is float2 between zero and one (lets say 0.123456789; 0.987654321) - which doesnt have to land exactly on pixel (lets say, texture is 90 px wide and you want pixel 33 -> 33 ÷ 90 = 0.366666period...) and you got "half pixel" which, if neighbouring pixel is colored, will make artefacts on sides of your sprite, but thats heavy OT :)

by (233 points)
selected by

Ah, so it really is a problem with the image, thanks. I'll try adjusting it or just use AnimatedSprite. Thank you very much for your detailed answer!

You are welcome :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.