GLBasic forum

Main forum => GLBasic - en => Topic started by: CCJ on 2010-Oct-08

Title: simplest way to display an animated png file?
Post by: CCJ on 2010-Oct-08
Hi all,

I am having some trouble creating what should be a simple animation for an iPhone app I'm working on--

Code (glbasic) Select

LOADANIM "yesnobuttons.png", 0, 295,300
FOR y=0 TO 19
  DRAWANIM 0, y, 0, 100
  SHOWSCREEN
  MOUSEWAIT
NEXT

MOUSEWAIT


The animation is supposed to draw two buttons rising up out of the ground for the user to press, but instead I just get crazy mangled looking results.  Is there an easy way to just load in and display a pre-made animation, and have it run through its frames in one location (i.e. not require any user input to etc. to change frames as in a walking animation).  Also, what's the best way to control the speed at which an animation iterates through its frames?  As you can see here I just made it pause at every frame so I could check on what was being displayed, but in the final app the animation should run smoothly on its own when called.
Title: Re: simplest way to display an animated png file?
Post by: Leginus on 2010-Oct-09
i would do something like
Code (glbasic) Select
LOADANIM "yesnobuttons.png", 0, 295,300
ani=0

WHILE KEY(01) = FALSE
   delta=delta+1
   IF delta>6   //Framerate of your choice
      INC ani
      IF ani>19
         ani=0
      ENDIF
   ENDIF
  DRAWANIM 0, ani, 0, 100
  SHOWSCREEN
WEND

Title: Re: simplest way to display an animated png file?
Post by: Ian Price on 2010-Oct-09
Leginus, your code won't work properly - as soon as delta is greater than 6 it will run through the entire animation before resetting delta to zero. While delta is less than (or equal to) six there will be no animation and only the last anim frame will be displayed.

What you probably meant is -

Code (glbasic) Select


LOADANIM "yesnobuttons.png", 0, 295,300

anim=0

WHILE TRUE

INC delta

IF delta>6
INC anim
delta=0
ENDIF

IF anim>19 THEN anim=0

DRAWANIM 0,anim,0,100

SHOWSCREEN

WEND
Title: Re: simplest way to display an animated png file?
Post by: Leginus on 2010-Oct-09
oops. its late :(
Title: Re: simplest way to display an animated png file?
Post by: Moebius on 2010-Oct-09
The only reason I can think of for why your results might be 'mangled' is if you've got the width and height of each frame wrong.
Creating in image with the frames side by side is the easiest way to load and use an animation - if you've got the height and width parameters right, it should work perfectly, and you can make it 'animate' more slowly by only changing the frame displayed once every few logic updates, as described below.