TGC Codebase Backup



image commands by Dimension

19th Dec 2005 21:43
Summary

A few functions for images



Description

A few functions for images
Free_Sprite - finds a unused sprite
Flip_image - flip the image verticly or horizontally
Image_Width - returns the image width
Image_Hieght - returns the image height
Resize_image - resizes the image to a specified size
Scale_image - scale the image using a percentage



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    function Free_Sprite()
   `find a unused sprite number
   for i = 1 to 1000
      if spr = 0
         if sprite exist(i)
         else
            spr = i
         endif
      endif
   next i
endfunction spr

function Flip_Image(img, vert, hor)
   spr = Free_Sprite()
   
   `create sprite
   sprite spr, 0, 0, img
   set sprite spr, 1, 0
   `flip vertical
   if vert = 1 then flip sprite spr
   `flip horizontal
   if hor = 1 then mirror sprite spr
   
   paste sprite spr, 0, 0
   
   `delete the old image and get the new image
   delete image img
   get image img, 0, 0, sprite width(spr), sprite height(spr)
   delete sprite spr
endfunction

function Image_Width(img)
   spr = Free_Sprite()
   
   `create sprite
   sprite spr, 0, 0, img
   set sprite spr, 1, 0
   
   `width of the image
   ret = sprite width(spr)
   
   `delete the old image and get the new image
   delete sprite spr
endfunction ret

function Image_Height(img)
   spr = Free_Sprite()
   
   `create sprite
   sprite spr, 0, 0, img
   set sprite spr, 1, 0
   
   `width of the image
   ret = sprite height(spr)
   
   `delete the old image and get the new image
   delete sprite spr
endfunction ret

function Resize_image(img, width, height)
   spr = Free_Sprite()
   
   `create sprite
   sprite spr, 0, 0, img
   set sprite spr, 1, 0
   
   size sprite spr, width, height
   
   `delete the old image and get the new image
   delete image img
   get image img, 0, 0, sprite width(spr), sprite height(spr)
   delete sprite spr
endfunction

function Scale_image(img, percent)
   spr = Free_Sprite()
   
   `create sprite
   sprite spr, 0, 0, img
   set sprite spr, 1, 0
   
   scale sprite spr, percent
   
   `delete the old image and get the new image
   delete image img
   get image img, 0, 0, sprite width(spr), sprite height(spr)
   delete sprite spr
endfunction