News:

Function Finder  Find all the functions within source code files

Main Menu

TheGameCreators Banner Animation Rendering Code (TGC)

Started by kevin, February 20, 2025, 10:21:20 AM

Previous topic - Next topic

kevin

  TheGameCreators Banner Animation Rendering Code  (TGC)


  This PlayBASIC program creates a dynamic banner display using images from a folder. The banners move toward the viewer (zooming down the Z-axis), while also fading in and gently oscillating using a sine wave effect. A scrolling version of the banners is displayed in the background for added visual interest.

How It Works:

1. Loading Banners
  - The program reads all image files from a specified folder.
  - Each image is loaded and stored in an array for use in the animation.

2. Setting Up the Scene
  - A camera is created to manage depth effects.
  - The main display area is prepared with a scrolling banner panel in the background.

3. Animating the Banners 
  - Each banner moves forward along the Z-axis.
  - A sine wave effect modifies their vertical position to create a floating motion.
  - Transparency (alpha) is adjusted based on depth to create a smooth fade effect.

4. Background Scrolling Panel
  - A separate function continuously scrolls banner images in the background.

5. Rendering the Scene
  - The banners are drawn in 3D perspective, adjusting size and position based on depth.
  - The program continuously updates and redraws the screen to create smooth animation.

6. User Interaction
  - Holding the mouse button speeds up the animation.
  - Pressing the spacebar exits the program.

  This program is a great example of using PlayBASIC for simple 3D-like effects with 2D images, using depth, transparency, and movement to create a visually engaging display.



 


 
PlayBASIC Code: [Select]
    positionscreen -9,getscreenypos()  
setmouse mousex(),100

// INSERT THE LOCAtION HERE
global path$="C:\Location_Of_Banner\images\"
readdir path$,"",0,0


Dim Vert#(256)

FrameRate = 30
z#=200

type tBanner
x#,y#
file$
image
depth#

Alpha#
Angle#
Endtype

dim Banner as tBanner list


global finalimage =-1

Dim ImageCache(10000)

// display the results
For Files=0 To GetDirSize()-1
If GetDirFileType(files)=1
file$=GetDirFile$(files)
AddBannerFromFile(file$)
EndIf
Next

Camera = newcamera()
cameracls camera,off

scenemaxzdepth 10000

SceneDEpth#=7000
ClipNearZ# = 400

Baseypos#=GetScreenHeight()*1.10


for each banner()
FinalImage =Banner.image
exit
next

setfps 30
swingradius#=100

do

FRameStep=1
if mousebutton()=1
FRameStep=25
endif
cls 0

lockbuffer
DrawBannerPanel(BaseXpos,BaseYpos#)
unlockbuffer

BaseYpos#-=(0.70*FRameStep)

setcursor 0,0
capturetoscene
clsscene


for each banner()
image=banner.image
y#=banner.y
z#=banner.depth+8*FrameStep

if Image=FinalImage
if z#>550
z#=550
swingradius#=curvevalue(0,swingradius#,20)
endif
endif


angle#=wrapangle(banner.angle+(2.5*FrameStep))
y#=(cos(Angle#)*SwingRadius#)
if Z#>50
Alpha#=1
if z#>(SceneDEpth#/2)
Alpha# = 1-((SceneDEpth#-z#)/(SceneDEpth#/2))
endif
if z#<ClipNearZ#
Alpha# = z#/ClipNearZ#
endif
capturedepth z#
DrawImageZ(IMage,0,y#,z#,alpha#)
endif


banner.depth = z#

banner.angle=angle#
if Z#>SceneDEpth#
Banner = null
continue
endif
next



drawcamera camera

CurrentSprite=GetFirstSprite()
while CurrentSprite
NextSprite=GetNextSprite(CurrentSprite)
deletesprite CurrentSprite
CurrentSprite=NextSprite
EndWhile


sync
loop spacekey()


Function DrawBannerPanel(BaseXpos,BaseYpos)
ScreenWidth=GetSurfaceWidth()
Width=400
Height=80
Count=ImageCache(0)
for lp =1 to Count-1
;; if (BaseYpos+ypos)>=0
image =ImageCache(lp)
drawimage image,BaseXpos+Xpos,BaseYpos+Ypos,false
;; endif
Xpos+=Width
if (Xpos>ScreenWidth)
Xpos=0
Ypos+=Height
endif
next

EndFunction

Login required to view complete source code


  Note: This code requires a series of banners (shown in video) but are NOT supplied !