please help, How to do make scrolling background?
Author |
Message |
nefer
|
Posted: Thu Dec 19, 2013 1:17 pm Post subject: please help, How to do make scrolling background? |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
side scroller, the background moves with my sprites(direct by arrow keys)
What is the problem you are having?
<Answer Here>
I don't know how to make it, no clue:(
Describe what you have tried to solve this problem
<Answer Here>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
<Answer Here> |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Raknarg
|
Posted: Thu Dec 19, 2013 1:36 pm Post subject: RE:please help, How to do make scrolling background? |
|
|
Do you know how to draw a background? Basically you just draw a background that's bigger than the screen, and include some kind of offset. For instance, if you move 5 to the right, you add 5 to the x offset. Them you draw the image at whatever position you want it at minus the offset. If your image is normally at 0, 0 when you start, you'll now draw it at -5, 0. |
|
|
|
|
|
nefer
|
Posted: Mon Jan 06, 2014 12:05 pm Post subject: RE:please help, How to do make scrolling background? |
|
|
But how am I suppose to make the ground move? |
|
|
|
|
|
Insectoid
|
Posted: Mon Jan 06, 2014 1:38 pm Post subject: RE:please help, How to do make scrolling background? |
|
|
Everything you draw that needs to move will need a variable to store an X value (an array might be useful here). Then you just need to change all of those values to move them. |
|
|
|
|
|
Raknarg
|
Posted: Mon Jan 06, 2014 4:46 pm Post subject: RE:please help, How to do make scrolling background? |
|
|
Here's a small example, I documented it. you are the red ball, with a grey building in the background:
Turing: |
setscreen("offscreenonly")
var input : array char of boolean
var offsetx, x, y : int := 0
x := 50
y := 20
loop
Input.KeyDown(input )
% Move left if you press a
if input ('a') then
x - = 2
% If player gets close to the edge, move screen instead of player
if x < 50 then
x := 50
offsetx + = 1
end if
% Move right if you press d
elsif input ('d') then
x + = 2
% If player gets close to the edge, move screen instead of player
if x > maxx- 50 then
x := maxx- 50
offsetx - = 1
end if
end if
% Player Drawing
Draw.FillOval(x, y, 10, 10, 12)
% Building Drawing
Draw.FillBox(100 + offsetx, 50, 150+offsetx, 200, grey)
View.Update
delay(2)
cls
end loop
|
Pretty simple. In my example I made it so the background only moves once you're close enough to an edge. You can make it so it only ever moves the background, whatever you want.
In any case, this is the basic concept. What I'm doing is storing a value offsetx which tells me how far off I'd like to draw the background. |
|
|
|
|
|
|
|