| Author | Message | 
		 
		| chaos 
 
 
 
 
 | 
			
				|  Posted: Mon Aug 08, 2011 2:05 pm    Post subject: Background for a side-scroller |  |   
				| 
 |  
				| I have an image that I want to use as a background for a side-scroller. The problem that I am having is looping the image infinitely. How do I go about this? |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
		 
		| Sponsor Sponsor
 
  
   |  | 
	 
		|  | 
				 
		| ProgrammingFun 
 
  
 
 
 | 
			
				|  Posted: Mon Aug 08, 2011 2:50 pm    Post subject: RE:Background for a side-scroller |  |   
				| 
 |  
				| Any code? |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| chaos 
 
 
 
 
 | 
			
				|  Posted: Mon Aug 08, 2011 3:51 pm    Post subject: Re: Background for a side-scroller |  |   
				| 
 |  
				| Sure, I put the code as an image. The first is the code and the second is the background. 
 
 
 
	
		
	 
		| Description: |  |  
		| Filesize: | 1.81 MB |  
		| Viewed: | 199 Time(s) |  
		| 
  
 
 |  
 
 
	
		
	 
		| Description: |  |  
		| Filesize: | 1.39 MB |  
		| Viewed: | 286 Time(s) |  
		| 
  
 
 |  
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| ProgrammingFun 
 
  
 
 
 | 
			
				|  Posted: Mon Aug 08, 2011 4:01 pm    Post subject: RE:Background for a side-scroller |  |   
				| 
 |  
				| Just to clarify, this background scrolls as the player moves along? |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| chaos 
 
 
 
 
 | 
			
				|  Posted: Mon Aug 08, 2011 4:23 pm    Post subject: Re: Background for a side-scroller |  |   
				| 
 |  
				| Not exactly. I want the background to scroll while the player moves freely about the screen. My goal is to first get the background scrolling in a seamless loop first, and then I wish to move onto player control. |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| crossley7 
 
 
 
 
 | 
			
				|  Posted: Mon Aug 08, 2011 8:51 pm    Post subject: Re: Background for a side-scroller |  |   
				| 
 |  
				| I would recommend having a variable(x) that contains the x position of the picture (which spot is at x = 0 on the screen) and a variable that holds the size of the picture(y) (unless it is a known number you will always use) then once it reaches a point where x+ screenx = y then you will draw the picture at x+screenx as well until x=y (the first picture has looped through) at which point you can reset x to 0. So the code might look like 
 
 	  | Turing: |  	  | 
setscreen ("offscreenonly")
const screenx = 600
const  picx = 2000
var  xposition = 0
loop
    Pic.Draw ( picid,-xposition,0 ,picCopy)
    if  xposition =  picx then 
        xposition = 0
    elsif  xposition + screenx >= picx then
        Pic.Draw ( picid,picx-xposition,0 ,picCopy)
   end if
   % Player movement and collision detection etc.
   View.Update 
   xposition+=1
end loop | 
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		|  |