Page 1 of 1

Help with basic sprite control

Posted: Fri Sep 14, 2018 4:03 am
by billybob884
So I'm experimenting with a very trimmed down version of the "sprite" sample project to better understand sprite control, and I'm having a little trouble. I've created a simple project that spawns a single sprite, then attempts to set its position using SPR_setPosition and the D-pad controls (I've attached the project file).

The sprite displays correctly, but my movement controls don't seem to work, it only nudges it in either X/Y direction by ~1pixel. I used VDP_drawText to display the coordinates on screen so I know the controls should be working, but the setPosition command doesn't seem to work how I'm expecting it to. Is there something obvious I'm missing, or do I just have a fundamental misunderstanding of how sprite movement works?

Thank you for your help

Re: Help with basic sprite control

Posted: Fri Sep 14, 2018 7:39 am
by Stef
Your coordinates are in fix32 type (fixed point number), so adding -1 or +1 will only modify from the minimal amount the fractional part.
If you want to add 1 pixel you need to add FIX32(1)

You should read this document :
https://github.com/Stephane-D/SGDK/wiki/Tuto-Maths

To understand how SGDK handle these fixed point numbers :)

Re: Help with basic sprite control

Posted: Fri Sep 14, 2018 6:23 pm
by billybob884
Ah, rookie mistake, trying to do math with dissimilar variable types. Obvious in hindsight! Just need to get used to the new int/float types, thank you!