Blink Animation Function and Demo by Trek17th Jan 2006 20:46
|
---|
Summary A simple function providing easy blink animation between two images with plenty of documentation. Description Oftentimes I've found it useful to have a simple blink animation between two images such as in the case of a blinking cursor, a TV static animation, or the like. This function, provides a simple and easy way of adding such an animation to your game with very little code. Not only does it allow you to specify the two images involved in the animation but also the time each will be displayed before switching. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com ` Blink Animation Function And Demonstration ` By Trek Software Manager D3 ` Copyright Free - Can be used in any way without credit ` www.treksoftware.tk ` Intial Setup. Not required for function to work correctly sync on sync rate 30 hide mouse autocam off position camera 0,0,0 point camera 0,0,10 color backdrop rgb(10,10,10) ` Dimensions critical for function to perform correctly. DIM StartTime(100) DIM EndTime(100) DIM BlinkStatus(100) ` A couple of demonstration images. Your images can have any number under 100 and be ` of any image type. load image "Mission Accomplished 1.png",1 load image "Mission Accomplished 2.png",2 ` A flat object for the purposes of demonstration. make object plain 1,3.56,1 position object 1,0,0,4 fade object 1,500 ghost object on 1 ` Main loop do ` The function works by returning the correct texture value in order to create a ` blink animation. For example, for the first .1 seconds the program runs, it will ` return the value "1" since the first image has the image number of 1. During the ` next .1 seconds, it will return the value of "2" since the second image specified ` as being part of the animation has an image number of 2. texture object 1,BlinkAnimation(1,2,.1) sync loop ` Function itself. Notice the three parameters - the first image in the animation, ` the second image in the animation, and the time delay desired before it switches ` the images. function BlinkAnimation(Image1,Image2,TimeDelay#) ` Checks to see if its a first time call for the specified image and sets the corresponding ` BlinkStatus dimension variable to 1. if BlinkStatus(Image1)=0 then BlinkStatus(Image1)=1 ` Sets the start time for that variable to the current computer timer and the end time ` for it to be displayed as the indicated number of seconds after the current time. if StartTime(Image1)=0 then StartTime(Image1)=timer() : EndTime(Image1)=timer()+(TimeDelay#*1000) ` Checks to see if the immage has been displayed for the appropriate amount of time ` and if so, switches the images by multiplying the BlinkStatus variable by -1. It also ` resets the StartTime for that image. if timer()>=EndTime(Image1) then BlinkStatus(Image1)=BlinkStatus(Image1)*-1 : StartTime(Image1)=0 ` Checks to see which image should be displayed and sets the ReturnVal variable (the one ` which will be returned) to the appropriate image number. if BlinkStatus(Image1)=1 ReturnVal=Image1 else ReturnVal=Image2 endif ` Returns the appropriate image number. endfunction ReturnVal |