News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Load Image Strip/Pages to an Array

Started by kevin, December 01, 2004, 09:29:14 AM

Previous topic - Next topic

kevin

This function loads an image and grabs then frame(s) upon it storing them in the passed array.



PlayBASIC Code: [Select]
Function Load_Anim(AnimFrames(),File$,Frames,FrameWidth,FrameHeight,TransparentColour) 
Index=GetFreeImage()
LoadImage file$,Index

width=GetImageWidth(index)
height=GetImageHeight(index)

Dim AnimFrames(Frames)
AnimFrames(0)=Frames

For lp=1 To frames
RenderToImage Index
FreeImage=GetFreeImage()
AnimFrames(lp)=FreeImage
GetImage FreeImage,Xpos,Ypos,Xpos+Framewidth,Ypos+FrameHeight
ImageMaskColour FreeImage,TransparentColour
Xpos=Xpos+Framewidth
If Xpos=>width Then Xpos=0: Ypos=Ypos+FRameHeight
Next
RenderToScreen
DeleteImage index
EndFunction




kevin

#1
This code loads an image strip/picture to an Array AsteroidAnim().  The mini example then animates and renders the frames from this array to the   screen.  




PlayBASIC Code: [Select]
 Dim AsteroidAnim(1)

Load_anim(AsteroidAnim(),"Asteroid32.png",16,32,32,RGB(255,0,255))
SetFPS 30

CurrentFrame=1

Do
Cls 0

DrawImage AsteroidAnim(CurrentFrame),x,100,1
Inc currentFrame
If currentFrame>AsteroidAnim(0)
CurrentFrame=1
EndIf

x=x+2
If X> GetScreenWidth() Then x=-50

Sync
Loop




; This function load an image strip into memory then cut it into
; set of smaller images. The Image indexes are stored within a passed
; array.



Function Load_Anim(AnimFrames(),File$,Frames,FrameWidth,FrameHeight,TransparentColour)
Index=GetFreeImage()
LoadImage file$,Index

width=GetImageWidth(index)
height=GetImageHeight(index)

Dim AnimFrames(Frames)
AnimFrames(0)=Frames

For lp=1 To frames
RenderToImage Index
FreeImage=GetFreeImage()
AnimFrames(lp)=FreeImage
GetImage FreeImage,Xpos,Ypos,Xpos+Framewidth,Ypos+FrameHeight
ImageMaskColour FreeImage,TransparentColour
Xpos=Xpos+Framewidth
If Xpos=>width Then Xpos=0: Ypos=Ypos+FRameHeight
Next
RenderToScreen
DeleteImage index
EndFunction




kevin

#2
Here's the above example in PlayBASIC project form..  The ARTWORK is from Xenon 2000.

Cor

Thanks Kevin,

Much clearer now :-)

gr.

cor

QuoteThis code loads an image strip/picture to an Array AsteroidAnim().  The mini example then animates and renders the frames from this array to the   screen.  

Dim AsteroidAnim(1)

Load_anim(AsteroidAnim(),"Asteroid32.png",16,32,32,RGB(255,0,255))
SetFPS 30

CurrentFrame=1

Do
 Cls 0

 DrawImage AsteroidAnim(CurrentFrame),x,100,1
 Inc currentFrame
 If currentFrame>AsteroidAnim(0)
  CurrentFrame=1
 EndIf

 x=x+2
 If X> GetScreenWidth() Then x=-50

 Sync
Loop
; This function load an image strip into memory then cut it into
;  set of smaller images. The Image indexes are stored within a passed
; array.
Function Load_Anim(AnimFrames(),File$,Frames,FrameWidth,FrameHeight,TransparentColour)
 Index=GetFreeImage()
 LoadImage file$,Index  
 
 width=GetImageWidth(index)
 height=GetImageHeight(index)

 Dim AnimFrames(Frames)
 AnimFrames(0)=Frames

 For lp=1 To frames
  RenderToImage Index
  FreeImage=GetFreeImage()
  AnimFrames(lp)=FreeImage
  GetImage FreeImage,Xpos,Ypos,Xpos+Framewidth,Ypos+FrameHeight
  ImageMaskColour FreeImage,TransparentColour
  Xpos=Xpos+Framewidth
  If Xpos=>width Then Xpos=0: Ypos=Ypos+FRameHeight
 Next
 RenderToScreen
 DeleteImage index
EndFunction

Cor de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
http://www.chordplanet.com