Discuss Scratch

concentrating
Scratcher
1 post

ScrollX

Anybody know a good script way to code this? I have tried a lot of ways but they do not work. Can anyone help me?
Chainmanner
Scratcher
100+ posts

ScrollX

First you must create a “ScrollX” variable. Then, for one platform, you must have the script "go to x (ScrollX + )“ encased in a forever API in order to put it at a certain position. After that, you would want to have arrow keys to scroll, to do that use an ”if“ script. It has to be in a forever block as well. It would work like this, for example: ”forever: if left arrow key pressed then change ScrollX by 2.5" Can't really describe much more than this, but I hope it helps!
Lone-Wolf
Scratcher
87 posts

ScrollX

I've helped people with scrolling before… I'll copy and past the same thing:

Well, to scroll you need tons of variables, operators, movement, etc. and if you're a beginner, it's quite complicated. I have a project that is simply a scrolling test, and you can see the inside to see how it works. I'll tell you how anyways, to go along.You will need a variable called Scroll Y for vertical, and a variable called Scroll X for horizontal. (I'm just explaining Scroll X, but Scroll Y is basically the same thing. Just Y's instead of X's)

The way these work is that when you press a particular button, it changes the variable by a certain amount, or you could just make it scroll automatically. (The bigger the amount the faster the speed) The Scratch screen consists of 480 pixels, so to make the backgrounds match up, you use this number in your script.

So if you're doing this based on arrows being pressed, it'll work this way. (If not, then just change the script and make it run in a loop automatically) When the right key is pressed, make it change Scroll X by -5. (Or a different amount if you want it faster or slower) And when you press the left key, make it change scroll X by 5.

Next for the first background, make it's X position constantly (with the forever block) go to Scroll X + 480 * 0. Now, dur, 480 times zero equals zero, but this makes it easier in the script to simply duplicate. So then duplicate this “Forever set X position to Scroll X + 480 * 0” and put it in your second background sprite, but instead of 480 * 0, set it to 480 * 1. Then continue doing the same thing with any other sprites you may have, increasing the Scroll X + 480 *… plus one more than the last.

I hope this helped! Here's my program to help you! You can use the script if you want, or simply for reference. Here's the URL:
http://scratch.mit.edu/projects/10160196/
turkey3
Scratcher
1000+ posts

ScrollX

Check the wiki under tutorials
lilkeyaisa
Scratcher
1 post

ScrollX

concentrating wrote:

Anybody know a good script way to code this? I have tried a lot of ways but they do not work. Can anyone help me?


first you use an when green flag is clicked then a forever loop and then change x by -5
deck26
Scratcher
1000+ posts

ScrollX

See if this helps https://scratch.mit.edu/projects/92682141/

Scrolling doesn't have to be complicated or involve ‘tons of variables’. The key is realising what you have is a moving window that shows you part of the ‘real world’. So what appears in your window depends where your window is and that's what scrollX tracks.
kmbush2016
Scratcher
1 post

ScrollX

u7i6ti687gny7ig87gyg8
cs1770571
Scratcher
5 posts

ScrollX

I need help with my project can anyone help me its called platformer.When i click the right arrow I will go to the top of the ground without doing anyhthing the same with the left arrow

Last edited by cs1770571 (Nov. 23, 2019 22:40:27)

deck26
Scratcher
1000+ posts

ScrollX

cs1770571 wrote:

I need help with my project can anyone help me its called platformer.When i click the right arrow I will go to the top of the ground without doing anyhthing the same with the left arrow
Please don't necropost. Create your own new topic. Ideally share the project.
ryanhtheyeetmaster
New Scratcher
1 post

ScrollX

turn cw () degrees
turn cw () degrees
turn cw () degrees
turn cw () degrees
turn cw () degrees
turn cw () degrees
turn cw () degrees
turn cw () degrees
turn cw () degrees
lol_dev
Scratcher
2 posts

ScrollX

Umm no necroposting :nerd:

Last edited by lol_dev (Feb. 17, 2022 12:49:32)

Powered by DjangoBB