Handle X and Y on sprites

Previous topic - Next topic

AndyH

Hi - Could we please have a function added to allow us to specify the x and y handle of each sprite.  I could not find any reference to doing this in the docs.

Code (glbasic) Select
SETSCREEN 640,480,0
LIMITFPS 60

BLACKSCREEN


LOADSPRITE "test.png", 0

GLOBAL ang = 0
GLOBAL size = 1

WHILE TRUE

DRAWSPRITE 0, 320,240

ROTOZOOMSPRITE 0, 320,240, -ang+45, size
ROTOSPRITE 0 , 320, 240, ang

INC ang,1
size = SIN(ang)*5

SHOWSCREEN
WEND
Get Image here:

First I draw the sprite normally at 320 by 240, the centre of the screen.  It starts to draw from the top left of the sprite so the sprite is not central on the screen.  I could write a function to wrap around the display of a sprite to take into account my own handle co-ordinates, and as long as I remember to apply this transformation to other things such as SPRCOLL it should be OK, however I think we need this built in.  Especially so when looking at the other sprite drawing routines...

I also do a ROTOSPRITE.  I see that the sprite rotates around it's centre, but it is still displayed at the same position as before.  Having a handle x and y position would make sense here for sure, as I could specify where I want it to rotate around.

Finally I do a ROTOZOOMSPRITE which suffers from the same rotation at the sprites centre, but the scale up and down will change the actual position of where the edges are drawn as you'd probably expect.

Also what if I need the centre of my sprite to rotate around is not the physical centre of the image?  I'd need to make my image bigger to compensate.  If we can specify the x and y handle this would not be an issue.

For compatibility with older programs which expect the handle on the sprite position to act as it does now, perhaps you could add a command that switches OFF automatic sprite handles in order to use the x and y handle.  By default it can be ON and the sprite commands can work as they do now.  ON and they will use the X and Y handle for the rotation of sprites.

EDIT:  So the code could look like the following -

Code (glbasic) Select
SETSCREEN 640,480,0
LIMITFPS 60
SETSPRITEHANDLES true

BLACKSCREEN


LOADSPRITE "test.png", 0
SPRITEHANDLE 0, 10, 5 // set the handle to be 10,5 for sprite 0.
// note that when a DRAWSPRITE or ROTOSPRITE is used to display the sprite at say pos
// 320, 240 GLB would automatically take 10 off the x pos, 5 off the Y pos and the ROTOSPRITE
// would rotate around this centre (10,5)

GLOBAL ang = 0
GLOBAL size = 1

WHILE TRUE

DRAWSPRITE 0, 320,240

ROTOZOOMSPRITE 0, 320,240, -ang+45, size
ROTOSPRITE 0 , 320, 240, ang

INC ang,1
size = SIN(ang)*5

SHOWSCREEN
WEND

Kitty Hello

Use Polyvector for that.
Or :D Make a bigger sprite, that has the pivot in the center ;)

AndyH

I've been able to get a nice solution for a handle on sprites as long as they do not rotate.  However rotations need the handles to be specified - can you add some support for this, even if it's just in rotations.

I do not want to make my images bigger just to offset the rotation pivot point.  That will waste far too much memory - a problem for the GP2X and PocketPC platforms.

Of course the ideal solution would be as suggested above and add a handle mode for all sprite commands (and collisions).  I think this would help make this command set richer.


BTW - I find that POLYVECTOR is slower, even when I only define my four points to display the image in the same way/size/rotation as the normal draw sprite routines.  I can't test at work to get the figures, but one of my first tests was to see how many sprites I could display on Windows and the PocketPC.  Both were noticably slower (with a smaller count of sprites before the frame rate dropped) when I used POLYVECTOR.  I ahven't tried using POLYVECTOR to rotate my sprites, so don't know how the speed of doing that compares with the speed of ROTOSPRITE but still, I'm sure you could do it faster if this is built in rather than coding around it with POLYVECTOR?

Kitty Hello

OK, you can use rotosprite, if you rotate the pivot point, too.
Something like this then:
http://www.glbasic.com/forum/viewtopic.php?pid=9615

AndyH

Thanks Gernot. Will try at home later but looks like it will do just what I need.

AndyH

Can I be cheeky?  How would you convert that for use as a Roto Zoom Sprite command?

Kitty Hello

hehehe.
Simply scale the sinp,cosp with the scale factor.