Using the fix16/fix32 typedef with the sprite engine

SGDK only sub forum

Moderator: Stef

Post Reply
BroOfTheSun
Interested
Posts: 33
Joined: Fri Dec 12, 2014 2:41 am
Location: USA - Chicago, IL

Using the fix16/fix32 typedef with the sprite engine

Post by BroOfTheSun » Mon Feb 16, 2015 3:54 pm

Within sprite_eng.c, the SPR_setPosition has the following lines of code:

Code: Select all

const s16 fx = x + 0x80;
const s16 fy = y + 0x80;
What do these lines of code do?

I'm using fix16 and fix32 types in my code to simulate floating point numbers. I'm trying to figure out what I can do to allow fix16 and fix32 to work with SPR_setPosition. Currently, I'm converting the fix16/fix32 numbers to integers, then passing them to the SPR_setPosition method. Can I adjust SPR_setPosition to accept fix16 or fix32, then remove these two lines of code from SPR_setPosition?

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Post by tryphon » Mon Feb 16, 2015 5:45 pm

i suppose they compute "fixed" coordinates of sprites : if you want a hardware sprite to be at top-left of the screen, you must give it coordinates of 128, 128.

I suppose Stef wanted this aspect to be transparent to the user so he can use "intuitive" coordinates.

Fix16/32 to int conversion is straightforward. Is it really worth bothering chaging the code ?

BroOfTheSun
Interested
Posts: 33
Joined: Fri Dec 12, 2014 2:41 am
Location: USA - Chicago, IL

Post by BroOfTheSun » Mon Feb 16, 2015 6:14 pm

I was trying to figure out if I should change the code. It looks like I shouldn't. I was also trying to understand those two lines of code, and what their purpose was. Thanks for the info. I will continue to work with my code as is.

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

Post by Stef » Mon Feb 16, 2015 10:04 pm

Yeah i did just that so coordinate 0,0 is really at position 0,0 and the method of course accept negative position parameters so the sprite can be partially clipped on left. And i think you indeed have to perform the fix16 to integer conversion before sending to this method. Anyway at some point you will have to convert it to integer coordinates.

Post Reply