Beginnner to sprites : Basic help needed

BlitzMax Forums/BlitzMax Beginners Area/Beginnner to sprites : Basic help needed

DannyD(Posted 2005) [#1]
Hi,
I have the following sprite set. Is it possible to use something like this to animate sprites using blitzmax ? THanks in advance.
[img]http://www.kickoffworld.net/wiki/index.php?title=Image:Fbgraph.png[/img]


Erroneouss(Posted 2005) [#2]
Yes.

LoadAnimImage:TImage(url:Object,cell_width,cell_height,first_cell,cell_count,flags=-1)

And to draw it put in the frame at the end:
DrawImage(image:TImage,x#,y#,frame=0)



Amon_old(Posted 2005) [#3]
Basically you have an animstrip of what I can see of that image you posted. What you need to work out is how big each cell of the image is then load it in using the loadanimimage command. Say for instance you have an animstrip with 4 different frames (Like the image you have but yours has more frames). You use loadanimimage to load the animstrip in and define the size of each frame and to also put how many frames there are.

You would do the following:
Global myimage:TImage = LoadAnimImage("where_the_image_is.png",cellWidth,CellHeight,0,NumberOF Frmaes,MASKEDIMAGE)

then when you draw it you do the following

DrawImage myimage,XPosition,YPosition,FrameNumber

framenumber:+1

if frame number > 4 then framenumber = 0




DannyD(Posted 2005) [#4]
Thanks alot guys.
I tried the following before coming back here and reading the replies.
myanimation = LoadAnimImage ("ko1.png",32,32,0,5)
Repeat
DrawImage (myanimation,50,50,x)
Flip
x=+1
Until x >=5
WaitMouse


My sprites are 32x32 http://www.kickoffworld.net/wiki/index.php?title=Image:Fbgraph.png


DannyD(Posted 2005) [#5]
Thanks for the replies.I got it working.I thought that drawimage increments the frames and outputs each one.I used a repeat loop that increments the count count until I reach the last frame.

Blitz goes through the frames extremely fast, is there a way of slowing it down ?


Amon_old(Posted 2005) [#6]
This should do it:


Global x:int = 0

Global myanimation:TImage = LoadAnimImage("Ko1.png",32,32,0,5)

Repeat
  
  Cls

     DrawImage myanimation,50,50,x

     x:+1
     if x > 4 then x = 0

  Flip
  Flushmem

UntilKeyHit(KEY_ESCAPE)



Frames in the LoadAnimImage command start from 0 and go up to how many frames there actually is. So if there are 5 frames it goes from 0 to 5. DrawImage command on the other hand starts counting from 0 so 0 is a frame. So for 5 frames it would actually be 0 to 4.

Hope that helps :)


Amon_old(Posted 2005) [#7]

Blitz goes through the frames extremely fast, is there a way of slowing it down ?


Yes. You have to use timers. A quick example would be :


Global FrameTimer = millisecs()
Global frame:int = 0

Global myimage:TImage = LoadAnimImage("myimage.png",32,32,0,5)


Repeat

  cls

      Drawimage myimage,50,50,frame
      
          If MilliSecs() > FrameTimer + 100
          FrameTimer = MilliSecs()
          frame:+1
          EndIf

          If frame > 4 then frame = 0

  Flip
  Flushmem

Until KeyHit(KEY_ESCAPE)



Hope that helps. :)


Ryan Moody(Posted 2005) [#8]
x:+1
if x > 4 then x = 0

Remember the Mod command Amon?!

Ryan


Amon_old(Posted 2005) [#9]
Remember the Mod command Amon?!


I'm going to be honest here and say I still have no clue on how to use it and when and where. :/


Ryan Moody(Posted 2005) [#10]
x = (x + 1) Mod 5


We're increasing x by 1, then storing in x the remainder of this value divided by 5. That way, x can never exceed 4 as the mod function would take it back down to 0.

Ryan


Amon_old(Posted 2005) [#11]
Still dont get it. Whats MOD doing and how does it reset it to 0?

You say MOD returns the remainder of the division. So if x = 2 then you divided by 5 MOD would return 1. Yes/No :confused:


Perturbatio(Posted 2005) [#12]
1 divided by 5 is less than 1 so mod returns the remainder: 1
2 divided by 5 is less than 1 so mod would return 2
3 divided by 5 is less than 1, mod returns 3
4 divided by 5 is less than 1, mod returns 4
5 divided by 5 is 1 so mod returns the remainder, which is 0

*EDIT*
a quick example:
Local x = 0
While count <10
Print "X = " + X
x= (X+1) Mod 5
Print "(X+1) Mod 5 = " + x
count:+1
Wend





DannyD(Posted 2005) [#13]
Thanks Amon but your code crashes once it executes.Compiling & linking are ok though.I'm using the latest BlitzMax on Tiger :(


Perturbatio(Posted 2005) [#14]
if you run it in debug mode, do you get an error message?
also, try putting strict at the top.


DannyD(Posted 2005) [#15]
Graphics 1280,854 was missing :(


DannyD(Posted 2005) [#16]
Ahh, The problem appears to be the fact that I didn't specify a graphics mode.
Graphics 1280,854 'set gfx mode was missing...


Amon_old(Posted 2005) [#17]
[snip]

Oops. Forgot to add the graphics mode in my code. :/ Sorry. :)


DannyD(Posted 2005) [#18]
Thanks for your help both of ye.


Perturbatio(Posted 2005) [#19]
I was just about to reply with that :) although I would suggest if you're going to be releasing a game don't work with such odd resolutions.
800x600 or 1024x768 seem standard.


DannyD(Posted 2005) [#20]
Indeed,I'm on a beginner so no release date soon :) The native resolution of my powerbook is 1280x854