Self Rolling Background
Author |
Message |
amz_best
|
Posted: Wed Sep 03, 2014 8:44 pm Post subject: Self Rolling Background |
|
|
What is it you are trying to achieve?
I am trying to make the background continuously roll on its own without any user pressing any buttons
What is the problem you are having?
This is my first day of coding, and i cannot figure out how to:
a) get the coordinates of pictures
b) how to make picture move down
c) How to merge 3 pictures to move down without any gaps in between
d) loop it all over again
Describe what you have tried to solve this problem
i've tried searching up commands of turing and this website for answers but i coudnt find any.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
As i said, this is my first day and so far, this is all i got.
Please specify what version of Turing you are using
http://tristan.hume.ca/openturing/
If someone could give me a rough example code, dat would be helpful for me to try 2 figure out. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Raknarg
|
Posted: Wed Sep 03, 2014 9:06 pm Post subject: RE:Self Rolling Background |
|
|
first of all, maxx div maxx is 1. maxy div maxy is also 1. This is because any number divided by itself is 1. maxx returns a number that is the width of the run window, and div is the function that performs integer division. For instance, if maxx is 500 and maxy is 400, this is what you're saying:
Pic.Draw (Space1, 500 / 500, 400 / 400, 0)
which is the same as:
Pic.Draw (Space1, 1, 1, 0)
This means you want Turing to draw the picture called Space1 with the bottom left of the picture at the coordinate (1, 1). |
|
|
|
|
|
amz_best
|
Posted: Wed Sep 03, 2014 9:13 pm Post subject: Re: Self Rolling Background |
|
|
setscreen ("graphics:max;max,")
var Space1 :int := Pic.FileNew ("space1.jpg")
loop
Pic.Draw (Space1, 0, 0, picCopy)
end loop
OK, so now i have re written my little code, but how do i get the Y coordinate? and how do i move the object down? |
|
|
|
|
|
Zren
|
Posted: Wed Sep 03, 2014 9:25 pm Post subject: RE:Self Rolling Background |
|
|
Draw it on a piece of paper.
Draw a box that represents your window. The bottom left is (0,0). The top right is (maxx, maxy).
Now draw a bigger box that's larger than your window. This box will represent your background picture. Since the bottom left coordinates of this box are variable (ergo they change/"move"), we need to represent with with variables.
Turing: |
var backgroundX, backgroundY : int := 0
|
The top right coordinates of our background box wiith be:
Turing: |
var backgroundX2 := backgroundX + backgroundWidth
|
Note that we made a two more variables (for the horizontal plane) to represent the top right X coordinate, and the with of the background. Do the same for the vertical plane (Y coordinate).
You can move the background around by assigning different values to backgroundX and backgroundY, then updating backgroundX2 and backgroundY2.
You can then "animate" the screen by using a loop, then redrawing all the items on the screen. Before redrawing, you can increment backgroundX to move the box right, giving the effect of moving the "camera" left. Decrementing backgroundX would move it left, giving the effect of moving the "camera" right.
Infinitely tiling your background is a bit more complicated, so get to having a scrolling background first. |
|
|
|
|
|
amz_best
|
Posted: Wed Sep 03, 2014 9:26 pm Post subject: Re: Self Rolling Background |
|
|
OMG I GOT IT!!!!
setscreen ("graphics:max;max,")
var y:int
y := 0
var Space1 :int := Pic.FileNew ("space1.jpg")
loop
Pic.Draw (Space1, 0, y, picCopy)
delay (50)
for i : 0 .. 10000 by 100
put i
end for
end loop
aLL I HAVE 2 DO NOW: merge 3 photos together with no gaps, slef scrolling is done xD
How do u get the height of a photo? if its 1920 x 1080. |
|
|
|
|
|
amz_best
|
Posted: Wed Sep 03, 2014 9:56 pm Post subject: Re: Self Rolling Background |
|
|
setscreen ("graphics:max;max,")
var y:int
var z: int
var a: int
y := 0
var Space1 :int := Pic.FileNew ("space1.jpg")
var Space2 :int := Pic.FileNew ("space2.jpg")
var Space3 :int := Pic.FileNew ("space3.jpg")
loop
Pic.Draw (Space1, 0, y, picMerge)
delay (40)
for i : 0 .. 5760 by 40
put i
end for
end loop
loop
Pic.Draw (Space2, 0, y, picMerge)
delay (40)
for i : 1920 .. 5760 by 40
put i
end for
end loop
loop
Pic.Draw (Space3, 0, y, picMerge)
delay (40)
for i : 3840 .. 5760 by 40
put i
end for
end loop
I tried to get all of the images to loop one after another, but there is only one picture looping. i cant figure out wats wrong... |
|
|
|
|
|
amz_best
|
Posted: Wed Sep 03, 2014 10:37 pm Post subject: Re: Self Rolling Background |
|
|
Hello Zren, i saw how simple ur y -= 40, cls and update was, so i tried it out and u were right, its not infinite but its better than my previous code xD
Does anyone know how to elaborate on Zren's idea? and make the scrolling forever? |
|
|
|
|
|
amz_best
|
Posted: Thu Sep 04, 2014 10:33 am Post subject: Re: Self Rolling Background |
|
|
Turing: |
View.Set("offscreenonly")
setscreen ("graphics:max;max,")
Draw.FillBox(0, 0, maxx, maxy, black)
const screeny := 1920
const picy := 1200
%1920 x 1200 is the res of my picture
var yposition := 0
var Space1 : int := Pic.FileNew ("space1.jpg")
var Space2 : int := Pic.FileNew ("space2.jpg")
var Space3 : int := Pic.FileNew ("space3.jpg")
loop
Pic.Draw (Space2, 0,-yposition, picCopy)
if yposition = picy then
yposition := 0
elsif yposition + screeny >= picy then
Pic.Draw (Space2, 0,picy-yposition, picCopy)
end if
View.Update
yposition+= 1
end loop
|
i FIGURED OUT A BETTER WAY!!! now all i have to do is make the images smooth enough so dat it looks like one image continuously scrolling! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
amz_best
|
Posted: Thu Sep 04, 2014 3:39 pm Post subject: RE:Self Rolling Background |
|
|
When i add other pictures, all i end up is with the first picture over laying the second one as soon as the second picture touches the botton on screen. |
|
|
|
|
|
Raknarg
|
Posted: Thu Sep 04, 2014 8:26 pm Post subject: RE:Self Rolling Background |
|
|
show us your code |
|
|
|
|
|
amz_best
|
Posted: Thu Sep 04, 2014 10:36 pm Post subject: Re: Self Rolling Background |
|
|
Turing: |
View.Set("offscreenonly")
setscreen ("graphics:max;max,")
Draw.FillBox(0, 0, maxx, maxy, black)
const screeny := 1920
const picy := 1200
%1920 x 1200 is the res of my picture
var yposition := 0
var Space1 : int := Pic.FileNew ("space1.jpg")
var Space2 : int := Pic.FileNew ("space2.jpg")
var Space3 : int := Pic.FileNew ("space3.jpg")
loop
Pic.Draw (Space1, 0,-yposition, picCopy)
if yposition = picy then
yposition := 0
elsif yposition + screeny >= picy then
Pic.Draw (Space2, 0,picy-yposition, picCopy)
end if
View.Update
yposition+= 1
end loop
|
|
|
|
|
|
|
|
|