Discuss Scratch

MistCat
Scratcher
21 posts

Having Trouble Understanding Code For Scrolling Platformer.

I've learned mostly by watching other people code, going into projects and seeing how it's done. However, I can't make sense of this string of code that I often run into while looking at scrolling platformers:

when green flag clicked
forever
set x to ((scrollX) + ((480) * (0)))
end

This code is taken from the project 8 Scrolling Demo by SampleProjectsTeam seen here: https://scratch.mit.edu/projects/583769/

What does ‘*’ mean? I'm rather confused, and always have been by this bit of code. Anyone care to dumb it down for me?
PutneyCat
Scratcher
500+ posts

Having Trouble Understanding Code For Scrolling Platformer.

The * means multiplied by.

480 x 0 = 0 so adding 480 x 0 doesn’t do anything. But the other similar terrain sprites add 480 x 1, 480 x 2 etc to kind of spread them out side by side.
MistCat
Scratcher
21 posts

Having Trouble Understanding Code For Scrolling Platformer.

PutneyCat wrote:

The * means multiplied by.

480 x 0 = 0 so adding 480 x 0 doesn’t do anything. But the other similar terrain sprites add 480 x 1, 480 x 2 etc to kind of spread them out side by side.
Wow, I never put that together. Thank you very much, this should be very helpful!
deck26
Scratcher
1000+ posts

Having Trouble Understanding Code For Scrolling Platformer.

https://scratch.mit.edu/projects/92682141/ may help you see why this works.
MistCat
Scratcher
21 posts

Having Trouble Understanding Code For Scrolling Platformer.

deck26 wrote:

https://scratch.mit.edu/projects/92682141/ may help you see why this works.
That did help a lot, thank you! I've bookmarked the page so I can reference it again in the future.
deck26
Scratcher
1000+ posts

Having Trouble Understanding Code For Scrolling Platformer.

MistCat wrote:

deck26 wrote:

https://scratch.mit.edu/projects/92682141/ may help you see why this works.
That did help a lot, thank you! I've bookmarked the page so I can reference it again in the future.
The big realisation for me was the idea that the screen is just a window onto the ‘real world’ so scrollx/y are just adjustments to the real world coordinates which tell you where something is in terms of screen coordinates. Once you see that the rest is relatively easy.

Powered by DjangoBB