UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on December 01, 2004, 09:29:14 AM

Title: Load Image Strip/Pages to an Array
Post by: kevin on December 01, 2004, 09:29:14 AM
This function loads an image and grabs then frame(s) upon it storing them in the passed array.



[pbcode]
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
[/pbcode]

Title: Load Image Strip/Pages to an Array
Post by: kevin on December 01, 2004, 10:17:21 AM
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.  




[pbcode]
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
[/pbcode]

Title: Load Image Strip/Pages to an Array
Post by: kevin on December 01, 2004, 10:19:08 AM
Here's the above example in PlayBASIC project form..  The ARTWORK is from Xenon 2000.
Title: Load Image Strip/Pages to an Array
Post by: Cor on December 01, 2004, 04:28:37 PM
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

[snapback]4911[/snapback]