Help with basic sprite control

SGDK only sub forum

Moderator: Stef

Post Reply
billybob884
Newbie
Posts: 5
Joined: Tue Aug 21, 2018 1:03 pm

Help with basic sprite control

Post by billybob884 » Fri Sep 14, 2018 4:03 am

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
Attachments
test.zip
Sprite movement test project
(106.66 KiB) Downloaded 2 times

User avatar
Stef
Very interested
Posts: 2774
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Help with basic sprite control

Post by Stef » Fri Sep 14, 2018 7:39 am

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 :)

billybob884
Newbie
Posts: 5
Joined: Tue Aug 21, 2018 1:03 pm

Re: Help with basic sprite control

Post by billybob884 » Fri Sep 14, 2018 6:23 pm

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!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests