i know what the variable scrollx or scroll or whatever you want to call it does, i want to know how it does it. this might have been answered somewhere else already, but could you answer it again then? it would make it easier for me, and probably others, to understand scrolling.
Offline
Alright, better place to explain how I know this. This is Scrolling:
[blocks]<when green flag clicked>[/blocks]
[blocks]<forever>[/blocks]
[blocks]<set x to( (( <{ ScrollX }> <+> (( 480 <*> number )) ))[/blocks]
Alright, all I know is that you multiply the ScrollX by the width of the stage (480). Of course the moving is on the stage, and it just changes ScrollX's value
Offline
With scratch you can easily see how the code does.
But if you don't get it it isn't hard to learn. All it is, is a variable tell sprites where to go on the x axis.
So if you make a code block like this:
set x to (scrollX)
If scrollX is equal to 1000 then the sprite's x position will be set to 1000.
And since the width of the screen for scratch is 480 we will want to move a sprite over by a multiple of 480 so that the sprites appear to be synchronized.
I am going to try to give you a visual example.
The _ represents a distance of 480 horizontally from point 0.
The - also represents a distance of 480 horizontally from point 0
the 1 is sprite one and the 2 is sprite two
The scrollX variable is set to 0
_______________________________________
1-----2--------------------------------------------------
If you count the "-"s, sprite 1 is in place 0 (it starts at zero, a lot of things in programming do) and sprite 2 is in place 6
So making sprite one go to that position is easy right? Just put this script
when green flag clicked
forever
set x to (scrollX)
end
Then sprite one will set it's x position to 0 like we want it to.
But there is a bit of a problem with sprite two. Since we don't want sprite two's x position to be 0 like sprite one's we will have to put in some code that can move it.
Since sprite two is in position 6 it means that its distance horizontally from position 0 is 480 multiplied by its position.
Well its position is 6 so this script should make sprite 2 move to position 6.
when green flag clicked
forever
set x to (scrollX+ (480*6))
end
There, now our sprite's x coordinate should be 480*6 which is equal to 2880.
Now that we have that set up what will happen if the user set the scrollX variable to 480? I will demonstrate with my visual.
_______________________________________
-1-----2--------------------------------------------------
Because the scrollX variable was changed from 0 to 480, our sprites move 480 more units to the right!
By changing the scrollX variable we can make the sprite go to any point along the x axis. If you synchronize your sprites using the 480*sprite position trick then you can create a large scrolling landscape.
Hope this was helpful. I really can't explain it any better.
Offline
Wow, I never actually thought of it that way (thought it does make sense. No confusion whatsoever)
Offline
wow. thanks so much. i get it now... lol now i won't have to use those tutorials anymore!
Offline
archmage didn't explain this though, scrolling enemies! he described stationary objects also, but this is for one that moves, each enemy will have their own scrollX obviously, so first we start with movement
if scrollX > myscrollX
then change scrollX by ***** (number must be positive(this is for moving left)
if scrollX < myscrollX
then change scrollX by****** (number must be negative(this is for moving right)
___________________________ end of script
this is for jumping:
if Yposition of sprite** < my Yposition
then set Yspeed to 4-6
set jumping to 1
change Y by Yspeed
repeat until touching ground color
change Y by Yspeed
change Yspeed by -0.2
once done with that
set Y speed to 0
set jumping to 0
___________________ end of script
now for sensing:
if not touching ground color and jumping = o
then repeat until touching ground color or jumping = 1
change Y by Yspeed
change Yspeed by -0.2
once done
if jumping = o
then set Yspeed to 0
if color a different color then at the feet, but similar is touching color ground color
then change Y by 5
(this allows you to go above the ground without bouncing)
(other if's can be added for sensors for things such as walls through more color sensors)
___________________ end of script
that's the basic design I use for side scrolling enemies sometimes they'll be more special and will require health variables and other things, but this covers a basic description
Offline
Neoroland wrote:
<when green flag clicked>
<if><mouse down?>
<switch to costume[1]>
<say[hoi]
<play sound[arggggg]
<say[im go ing to kill you]
<switch to costume[black]
lol
what's this got to do with anything?
Offline
actually the variable scrollx doesnt make it scroll all it does is keep track of numbers so the script doesnt have to be gigantor.
what makes the thing scroll is were you set x to scrollx*480/number or what ever it is.
Offline
coolstuff wrote:
Neoroland wrote:
<when green flag clicked>
<if><mouse down?>
<switch to costume[1]>
<say[hoi]
<play sound[arggggg]
<say[im go ing to kill you]
<switch to costume[black]
lolwhat's this got to do with anything?
uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh..................................*runs t astalia*
Offline
Once you understand the concept of how a function works such as scrolling, it all makes seance and you will start learning more of how widely used each and ever block has the potential. I find that a good way to under stand how variable based functions (once again like scrolling) works you have to 'mentaly' give the variable a random number. For example if i had 3 backgrounds that I want scrolling, i could quite simply use something like this:
Background1: x postions is equal to ([scrollx]+(0*480)) Background2: x postions is equal to ([scrollx]+(1*480)) Background3: x postions is equal to ([scrollx]+(2*480))
Although this will give me a functioning script (i haven't used this code in months, so apology if its incorrect), if i simply copy and paste it, I haven't actually learned anything.
However lets mentally imagine that our variable (scrollx) is any random number, for example 450.
this is what it will look like:
Background1: x postions is equal to ([450]+(0*480)) which is: x postions is equal to ([450]+0) which is: x postions is equal to 450 Background2: x postions is equal to ([450]+(1*480)) which is: x postions is equal to ([450]+480) which is: x postions is equal to 930 Background3: x postions is equal to ([450]+(2*480)) which is: x postions is equal to ([450]+960) which is: x postions is equal to 1410
so
background 1's x is 450
background 1's x is 930
background 1's x is 1410
you might notice now that those x positions have one key distinction. their all 480 positions apart. Now is makes seance because thats the same distance as the stage's width, which must mean that their exactly aligned and a constant distance without any overlapping.
Now you know more then just what works. Now you know how it works.
Offline
CFCRubiks wrote:
Alright, better place to explain how I know this. This is Scrolling:
[blocks]<when green flag clicked>[/blocks]
[blocks]<forever>[/blocks]
[blocks]<set x to( (( <{ ScrollX }> <+> (( 480 <*> number )) ))[/blocks]
Alright, all I know is that you multiply the ScrollX by the width of the stage (480). Of course the moving is on the stage, and it just changes ScrollX's value
It doesnt work!
Offline
If your object is
<{ scrollX }>+480
then when scrollX is -480, it will be in the center because 480 and -480 cancel out
So if you want your character to move forward, you actually have to move everything else back (unless there is no character, then everything is the right way round)
Offline
I still don't get it, can someone just show me what to put on my scripts, that's all I'll need.
Offline