Help with Polyvector animation

Previous topic - Next topic

AlienMenace

Going through the forum, I think I have the hang of drawing sprites using polyvector but I am having difficulty figuring out how to draw animated sprites.
I am looking at replacing this:

LOADANIM "explosions.png",150,50,50
DRAWANIM 150, anim_frame, x, y

With a method that uses polyvector.
Thanks
Apps published: 3

Ian Price

Here's a simple routine that displays an animated polyvector (32x32pixels) at position X,Y. You can load the image in with LOADSPRITE OR LOADANIM.

Code (glbasic) Select
SETCURRENTDIR("Media") // go to media files

LOADSPRITE "anim.png",1

LOCAL dlay,anim,x,y

x=300
y=200

WHILE TRUE

INC dlay // Animation speed

IF dlay>7
INC anim // Animation frame
dlay=0
ENDIF

IF anim>5 THEN anim=0

STARTPOLY 1
POLYVECTOR 0+x,0+y,0+anim*32,0
POLYVECTOR 32+x,0+y,32+anim*32,0
POLYVECTOR 32+x,32+y,32+anim*32,32
POLYVECTOR 0+x,32+y,0+anim*32,32
ENDPOLY

SHOWSCREEN

WEND


[attachment deleted by admin]
I came. I saw. I played.

AlienMenace

Cool, thanks! Is there anyway to retrieve the frame size info dynamically from an image loaded with Loadanim?

Cheers.
Steve
Apps published: 3

Ian Price

Ummm... If you've loaded an image (or set of images) with LOADANIM you already know the framesize of each image, as you need to put that into the command for it to work - LOADANIM "image.PNG", ID#, SIZEX, SIZEY. Just save the info into an array if you need it later.
I came. I saw. I played.

AlienMenace

Yeah, well I was hoping to get away from a lookup array and let a routine handle the sizing issue on it's own. Anyhow, not a big deal.

Thanks
Apps published: 3

Wampus

AlienMenace you might find useful some functions I wrote that mimic the default GLBasic sprite commands with POLYVECTOR equivalents, including rotation and resizing. The basic code is in this thread here. It uses a predefined lookup array for sprite co-ordinates but you could change that for your purposes.

PNG files contain the size of the image at offset 16 (width) and 20 (height). There are also custom fields in a PNG file that you could use to specify the x-width of an animation. Your app could use this information to read any PNG file as a potential animation.