GTcreyon / SM63Redux

Code base for Super Mario 63 Redux
https://sm63redux.com
Mozilla Public License 2.0
199 stars 28 forks source link

Refactor backgrounds #184

Closed Koopa1018 closed 8 months ago

Koopa1018 commented 1 year ago

Description of changes

Unites all background scripts into one multi-purpose bg_plane.gd script. This will make it easier to author new backgrounds.

bg_plane.gd extends TextureRect, as the old scripts did. It is designed for canvas objects, and is thus not useful for making terrain or other such objects move with parallax--that will have to be implemented separately.

Apart from what it inherits from TextureRect, it has three features: infinite looping, parallax factor, and autoscroll.

Infinite looping works the same way as it did in hills.gd, but it's been extended to work on both X and Y axes. The effect can be enabled/disabled per axis to make infinite horizontal/vertical strips instead of full-screen planes--but it can also be enabled/disabled per side of the object, meaning it's theoretically possible to have e.g. an object that extends infinitely upwards, but ends if you go down far enough. This feature hasn't yet been tested much, and in fact I'm not sure there's much point to it, but here it is. (It'll be much more useful in conjunction with ColorRects--extending a plane with an infinite expanse of color. That can't happen yet, though.)

Parallax factor is how much a plane moves relative to the camera (on each axis). A value of 0 means the plane is fixed in screen space, while a value of 1 means the plane moves at the same speed as an object in the foreground. Values higher than 1 are also possible, and will make the plane pass the camera faster than the level objects; this is useful for putting things in the extreme foreground, though it's unclear whether background planes will even be needed in that context.

Autoscroll is fairly self explanatory, and can also be set per axis. The clouds in the current background use this to appear to drift by.

The currently-existing background has been upgraded to use these new scripts. It doesn't look exactly the same as it used to; I'd fix that, but it's getting replaced soon anyway.

In the future, I would like to add some kind of "periodic" looping, which doesn't stretch the plane out infinitely but rather produces infinite spaced-out copies of it. For the indoorsy areas of the game, this could be useful for creating rows of pillars, and in conjunction with autoscrolling, it could be used to make flotsam and jetsam floating down e.g. a river.... But I haven't added that yet, and since it's not yet super pressing, I'll leave it for the future. (May be best to save that for the traditional-sprite parallax, come to think of it.)

Issue(s)

Need these tools to implement new backgrounds.

jaschutte commented 1 year ago

This feature currently breaks the tutorial levels; image Could you take a look at this?

GTcreyon commented 1 year ago

This PR has a somewhat disjointed commit history. Why does it include a merge from the 4.1 branch? What happened here? o-o

I'm not quite sure how to resolve this issue other than ditching this PR and reimplementing the intended changes, but if anyone has any guidance, feel free to point it out.

Koopa1018 commented 1 year ago

The 4.1 branch merge was intended to future-proof it. I consider it out of scope of the 4.1 branch (it's not fixing upgrade bugs, after all), but on the other hand, merging it into master seems unwise before a big change like 4.1 hits every file in the repo (and causes merge conflicts outside the scope of the relevant PRs).

Rebasing it to merge into the 4.1 branch seems to have cleaned up the commit history a good bit, at least. Going to convert to draft so nobody's tempted to merge it before #200 closes.

GTcreyon commented 10 months ago

Is this PR still relevant, given that we're redoing the background art? Or, perhaps that should be an extension of this PR?

Koopa1018 commented 10 months ago

This is a prereq for the background redo. It does need some reconsideration, given that I didn't know ParallaxBackground existed when I did the refactor 😅

The new background actually already has its own branch, asset-new-grass-bg. It's based on this one. Not sure I ever updated it for 4.1....

Koopa1018 commented 8 months ago

Refactored PR to use the Godot-native ParallaxLayer and ParallaxBackground nodes instead of a bg_planes script. This should theoretically be both easier to maintain and faster, and it can do everything that the original version can do except for autoscroll (which I've reimplemented as a simple script) and one-sided infinite strips (which can be implemented likewise if they're ever needed).