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
Help with basic sprite control
Moderator: Stef
-
- Interested
- Posts: 18
- Joined: Tue Aug 21, 2018 1:03 pm
Help with basic sprite control
- Attachments
-
- test.zip
- Sprite movement test project
- (106.66 KiB) Downloaded 170 times
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Help with basic sprite control
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
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
-
- Interested
- Posts: 18
- Joined: Tue Aug 21, 2018 1:03 pm
Re: Help with basic sprite control
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!