Smooth Backdrop Scrolling

Blitz3D Forums/Blitz3D Beginners Area/Smooth Backdrop Scrolling

LeftyGuitar(Posted 2014) [#1]
Hello,

I am trying to get my background to scroll smoothley. It scrolls, but when it gets to the edge of the screen, it resets itself, and you can see some of the screen cleared. I'd like the backdrop image to scroll smoothley without seeing the blank part of the screen. I'll post my code.

const MAX_WIDTH = 800
const MAX_HEIGHT = 600

;note backdrop is 640 by 480
Global BackdropImg = LoadImage("Backdrop.bmp")
		Scroll_X = Scroll_X - 2
		If Scroll_X <= -MAX_WIDTH Then
			Scroll_X = 0
		EndIf
		
		If GameScreen = True Then
			DrawImage BackdropImg,Scroll_X + MAX_WIDTH,Scroll_Y
		EndIf


I can post more code if it is needed.


RemiD(Posted 2014) [#2]
Firstly about the color of the background, you can color it with :
ClsColor(R%,G%,B%) ;R,G,B being an int between 0 and 255
Cls()

Secondly about the screen being cleared, i am not sure what you mean.
You can try to add this in your mainloop to see if this avoid the "screen cleared"


If this does not help, post a simplified code example so we can see what you are trying to do.


LeftyGuitar(Posted 2014) [#3]
That did not work, so I'll post more of my code.

Const MAX_WIDTH = 640
Const MAX_HEIGHT = 480
Const MAX_DEPTH = 32

Const MAX_FPS = 60
Const MAX_TICKS# = 1000.0

Const KEY_ESC = 1
Const KEY_ENTER = 28
Const KEY_SPACE = 57
Const KEY_LEFT = 203
Const KEY_RIGHT = 205
Const KEY_UP = 200
Const KEY_DOWN = 208
Const KEY_LEFTCTRL = 29
Const KEY_F2 = 60

Global TitleImg = LoadImage("Title.bmp")
Global GameoverImg = LoadImage("Gameover.bmp")
Global BackdropImg = LoadImage("Backdrop.bmp")
Global PlayerImg = LoadImage("PlayerShip.bmp")
Global EnemyImg = LoadImage("EnemyShip.bmp")
Global BulletImg = LoadImage("Bullet.bmp")

Graphics MAX_WIDTH,MAX_HEIGHT,MAX_DEPTH
SetBuffer BackBuffer()

Type Player
	Field Health
	Field Lives
	Field X#
	Field Y#
	Field Width
	Field Height
	Field X_Vel#
	Field Y_Vel#
	Field Move_Up
	Field Move_Down
	Field Move_Left
	Field Move_Right
	Field Fire_Bullet
	Field Hit
	Field Dead
	Field Respawn_Time#
	Field Offset_X#
	Field Offset_Y#
	Field Visible
	Field Points
End Type

Type Enemy
	Field Health
	Field Lives
	Field X#
	Field Y#
	Field Width
	Field Height
	Field X_Vel#
	Field Y_Vel#
	Field Hit
	Field Dead
	Field Points
	Field Move_Up
	Field Move_Down
	Field Move_Left
	Field Move_Right
	Field Respawn_Time#
	Field Offset_X#
	Field Offset_Y#
	Field Visible
End Type

Type Bullet
	Field X#
	Field Y#
	Field X_Vel#
	Field Y_Vel#
	Field Visible
	Field Life
	Field Width
	Field Height
End Type

Global Scroll_X = 0
Global Scroll_Y = 0

Global TitleScreen = True
Global GameScreen = False
Global GameoverScreen = False

Global gPlayer.Player = New Player
Global gEnemy.Enemy = New Enemy
Global gBullet.Bullet = New Bullet

Function GameLoop()

	While Not KeyHit(KEY_ESC)
		
		Cls()
		
		GameTime = MilliSecs()
		
		FPS# = MAX_TICKS / (GameTime - GameTime2)
		
		GameTime2 = GameTime
			
	   If TitleScreen = True Then
			Cls
			DrawImage TitleImg,0,0
	   EndIf	
		
		If KeyHit(KEY_ENTER) And TitleScreen = True Then
			TitleScreen = False
			GameScreen = True
		EndIf
		
		Scroll_X = Scroll_X - 2
		If Scroll_X <= -MAX_WIDTH Then
			Scroll_X = 0
		EndIf
		
		If GameScreen = True Then
			DrawImage BackdropImg,Scroll_X + MAX_WIDTH,Scroll_Y
		EndIf
		
		Text 1,1,"FPS:" + Int(FPS#)
	
		Flip
	Wend

End Function

GameLoop()



RemiD(Posted 2014) [#4]
Make a simplified code example that i can run
or
take a screenshot of the problem
or
describe the problem with more details
i can't guess what is displayed on your screen and what you want to have displayed.


LeftyGuitar(Posted 2014) [#5]
[img http://s1310.photobucket.com/user/LeftyGuitarx/media/BackdropImg_zpsfbb34692.png.html?filters[user]=140600659&filters[recent]=1&sort=1&o=0]

As you can see. The backdrop starts scrolling from the right of the screen, then moves till it reaches the left side, then starts over. What I'd like it to do is to have the backdrop take up the full screen and scroll endlessly without any issues.


Kryzon(Posted 2014) [#6]
Try the following:
		Scroll_X = Scroll_X - 2
		If GameScreen = True Then
			TileBlock( BackdropImg, Scroll_X, 0 )
		EndIf
It uses the TileBlock command.


RemiD(Posted 2014) [#7]
Yes or draw the image 2 times... At 2 different offsets.


LeftyGuitar(Posted 2014) [#8]
Thank you, the tileblock command works.