BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Scrolling background"
, by crazy_gaz_2001
OK pretty obvious but to do a scrolling background you need to make it move the opposite direction from your character.
Code
;First thing I like to do is give the program a title. apptitle "Scrolling Background demo" ;Then we set the Graphics mode graphics 800,600,false,2 ;then we set the buffer setbuffer backbuffer() ;loading our images is essential, for arguments sake I have used the names BG and character. ;below loads up the background global background=loadimage ("BG.bmp") ; loads the Background ;below loads up the character and because the chances are it will be animated we need the height,width,,starting frame,ending frame global character=loadanimimage ("character.bmp",128,111,0,6) ;now we mask the images, I prefer the crappy pink color. maskimage background,255,0,255 maskimage character,255,0,255 ;then we need to set our variables global characterx=160 global backgroundx#=0 dir=0 ;essential for preventing going backward (thanx to planetidiot.com for teaching me that) ;now we need to start our main loop. repeat cls ;below draws the background tileimage background,backgroundx,0 ;check the left and right arrow keys keyright=KeyDown(205) keyleft=KeyDown(203) ;right increases your x position, left decreases it characterx=characterx+keyright-keyleft ;should you be animating? If keyright Or keyleft walking=True Else walking=False EndIf ;below states that if you move right the background moves left If keyright walking=True backgroundx=backgroundx#-0.5 EndIf ;below states that if you move left the background moves right If keyleft walking=True imgx=imgx+0.5 EndIf ;if not, just stand there If walking=False frame=0 framedelay=0 Else ;other wise.... ;make sure you aren't standing there If frame=0 Then frame=1 ;this slows down your animation framedelay=framedelay+1 ;once you've delayed long enough... If framedelay>10 ;increase your walk variable walk=walk+1 ;There are 6 steps to the walking animation ;we want walk to reset to 0 after we pass walk=3 If walk>2 Then walk=0 ;we want to reuse the 2nd walking frame If walk=2 Then frame=0 Else frame=walk+1 ;reset the framedelay counter for next time framedelay=0 If walk > ImageWidth(background) + 250 Then TileBlock background,backgroundx,0 EndIf EndIf EndIf If keyright dir=0 ElseIf keyleft dir=1 EndIf ;if dir=0 then this will be 0 and have no effect on your animation frame. ;if dir=1 then this will be 4 and will use the animation frames where ;the guy is facing left. direction=(3*dir) ;draws the character DrawImage character,characterx,185,frame+direction ;makes it so you can't walk off screen but the background still movesIf characterx > 600 Then characterx=600 EndIf ;does the same for the other side If characterx < 128 Then characterx=128 EndIf ;thanks to planetidiot.com for some of the walking code the rest is mine. ;ends the loop until keyhit(1) ;ends the program end
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations