Stopping the background from scrolling

BlitzPlus Forums/BlitzPlus Programming/Stopping the background from scrolling

En929(Posted 2009) [#1]
I was wondering what do I do if I wanted the background to stop scrolling at a specific point. That is, after the character collides with a post, I want the background to become a still screen.


Hence, I guess my other question is how do I stop a keydown command (or commands like this) and go back to such again if I need it? At first, I tried the Function, and Goto commands, but maybe I had something missing form the code when I tried it.

Below is a condensed example with notes on what I'm trying to do now.


Graphics 1640, 1000
SetBuffer BackBuffer ()


;----------------------------------------------------------------------------

;Load Items

HENRY = LoadAnimImage ("Move2.png",400,370,0,13)
BACKGROUND = LoadImage ("BackgroundTree.jpg")
BACKGROUND2 = LoadImage ("Spaceship.jpg")	
PLATFORM = LoadImage ("Big Platform2.png")
POST = LoadImage ("Border.png")

Type HENRY

	Field x,y
	
	Field frame 
	

End Type 

Type POST 

	Field x,y
End Type 

Type BACKGROUND

	Field x,y
	
	Field image

End Type


Type PLATFORM

	Field x,y
	
End Type


h.HENRY = New HENRY
h\x = 500
h\y = 300
h\frame = 0


b.BACKGROUND = New BACKGROUND
b\x = 150
b\y = 150
b\image = BACKGROUND

p.PLATFORM = New PLATFORM
p\x = 100
p\y = 300


pst.POST = New POST

pst\x = 800
pst\y = 180


While Not KeyDown(1)

		Cls 
		


TileImage (b\image,b\x,b\y)	


;after my character gets to this post, I was trying to make it so that the background doesn't scroll anymore (see keydown)

If (pst <> Null) Then 
			DrawImage (POST,(b\x + pst\x),pst\y)
					If ImagesCollide (HENRY,h\x,h\y,0,POST,pst\x,pst\y,0) Then
												
											
					EndIf 		
EndIf 	

If KeyDown (57)
 
h\y = h\y -80
			
		
			
EndIf 



If Not KeyHit (57)

 h\y = h\y + 10

EndIf 


;I'm trying to stop the b\x = b\x - 3 in the Keydown (205) section, 
; and the b\x = b\x + 3 in Keydown (203) section after my
; character collides with the post.


If KeyDown(205)
		


		b\x = b\x - 3
		h\frame = h\frame + 1
		
		If h\frame > 2 Then 
		h\frame = 0
		
		EndIf 

EndIf 
  

		If KeyDown(203)


		b\x = b\x + 3
		h\frame = h\frame + 1
		

		If h\frame > 12 Then
		h\frame = 6


       EndIf

EndIf   
  

		


DrawImage (HENRY,h\x,h\y,h\frame) 


DrawImage (PLATFORM,(b\x + p\x),p\y)
If ImagesCollide(HENRY,h\x,h\y,0,PLATFORM,(b\x + p\x),p\y,0) Then 

		
	    h\y = 310
	
Else 

		h\y = h\y + 10


		
EndIf 

Flip

Wend




En929(Posted 2010) [#2]
Here's what I did to stop the background from moving... I simply drew another background (the same background) over the moving one, and used the goto command to change the controls. This way worked, but I think me being able to change the controls in the way that I did was probably pure luck, because it's quite a process trying to revert back to the old controls and switch them up at will, I think.


Yeshu777(Posted 2010) [#3]
Wouldn't it be easier to check that character x position is that of the post and then do not increment the background x offset?

or quite simply, only increment the background x pos when the character has not reached the post x position?


En929(Posted 2010) [#4]
Yeah, I admit I took the long way. When taking the long way, it seems that I learn more about the short way sometimes. I actually took that part out of my game and kept still background images altogether, but I’m going to revisit that part in a condensed version just to learn how it works (and try what you said) and maybe put it back in after I get it


Pineapple(Posted 2010) [#5]
I have two tips for you here:

First, you should learn to properly indent code. It will help yourself and others very greatly when reading your code.

Also, Goto is horrible and evil and devours poor little babies. Never use it, not even as a last resort. There is always a better way to go. Every time you execute the Goto command, a baby is eaten. You don't want that, do you?


En929(Posted 2010) [#6]
First, you should learn to properly indent code. It will help yourself and others very greatly when reading your code.


I'm working on it B+man... I'm working on it.