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?
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
ProgrammingFun
![](http://compsci.ca/v3/uploads/user_avatars/11682880074bcb590d30b0a.png)
|
Posted: Mon Aug 08, 2011 2:50 pm Post subject: RE:Background for a side-scroller |
|
|
Any code?
|
|
|
|
|
![](images/spacer.gif) |
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: |
165 Time(s) |
![scrollingBackground.bmp](uploads/attachments/thumbs/t_scrollingbackground_811.bmp)
|
Description: |
|
Filesize: |
1.39 MB |
Viewed: |
247 Time(s) |
![Background.t Code.bmp](uploads/attachments/thumbs/t_backgroundt_code_449.bmp)
|
|
|
|
|
|
![](images/spacer.gif) |
ProgrammingFun
![](http://compsci.ca/v3/uploads/user_avatars/11682880074bcb590d30b0a.png)
|
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?
|
|
|
|
|
![](images/spacer.gif) |
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.
|
|
|
|
|
![](images/spacer.gif) |
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
|
|
|
|
|
|
![](images/spacer.gif) |
|