Side Scrolling Considerations

A forum to share your demonstrations stacks, fun stacks, games, etc.
Post Reply
User avatar
richmond62
Posts: 2870
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Side Scrolling Considerations

Post by richmond62 »

Movement that looks even vaguely realistic on a computer is notoriously difficult: one of the considerations is parallax.

https://en.wikipedia.org/wiki/Parallax
-
I wouldn't recommend looking at the animated GIF for very long: personally I began to feel queasy in about 15 seconds. 8-)
-
Parallax.gif
Parallax.gif (703.41 KiB) Viewed 170 times
-
Screenshot 2024-02-18 at 20.02.20.png
Screenshot 2024-02-18 at 20.02.20.png (538.76 KiB) Viewed 174 times
-
Tear this to pieces, see what I have done, and if you feel brave try to make the motion less clunky. 8-)
Attachments
SIDEWAYS.oxtstack.zip
(105.99 KiB) Downloaded 27 times
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 1636
Joined: Tue Dec 21, 2021 9:10 pm
Location: Britain (Previously known as Great Britain)
Contact:

Re: Side Scrolling Considerations

Post by tperry2x »

I see what you mean, it's very juddery, for want of a better phrase.

This is how it works on my test system in the spare room, which is only an i5 processor - but you'd think a 2GHz i5 should be able to handle something so seemingly simple:
https://www.tsites.co.uk/otherstuff/lc- ... r-wolf.m4v

Here's another example:
https://www.tsites.co.uk/otherstuff/lc- ... xample.mp4

Downloadable livecode stack to pull apart:
https://www.tsites.co.uk/otherstuff/lc- ... 2.livecode
User avatar
tperry2x
Posts: 1636
Joined: Tue Dec 21, 2021 9:10 pm
Location: Britain (Previously known as Great Britain)
Contact:

Re: Side Scrolling Considerations

Post by tperry2x »

Also, some more 'fun and games'
https://www.tsites.co.uk/otherstuff/Cod ... -Source.7z
This eBook PDF was originally published and sold in 2014, but is now released for free under the Creative Commons license: Attribution-NonCommercial 4.0 International.
pong.png
pong.png (2.46 KiB) Viewed 148 times
23matches.png
23matches.png (75.38 KiB) Viewed 148 times
3disomaze.png
3disomaze.png (27.36 KiB) Viewed 148 times
textadventure.png
textadventure.png (24.63 KiB) Viewed 148 times
tetris.png
tetris.png (26.04 KiB) Viewed 148 times
lunarlander.png
lunarlander.png (5.41 KiB) Viewed 148 times
towerjump.png
towerjump.png (91.6 KiB) Viewed 148 times
doctoreliza.png
doctoreliza.png (11.3 KiB) Viewed 148 times
spiderhunt.png
spiderhunt.png (10.78 KiB) Viewed 148 times
User avatar
OpenXTalkPaul
Posts: 1665
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: Side Scrolling Considerations

Post by OpenXTalkPaul »

Thanks for posting this Richmond.

I played around with it for a little while. I added some judicial use of lock/unlock screen commands and 'set loc' instead of 'moves' commands to get bit faster run frame rate for the player/animal image frames. That bottom grass layer would be better as a smaller original, what I mean is you should crop off a lot of those transparent pixels above the grass,making an image that is smaller in height and then position it by bottom edge to the bottom of the card. Those extra alpha channel pixels are not needed and taking up memory and cpu time.
xAction
Posts: 285
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: Side Scrolling Considerations

Post by xAction »

tperry2x wrote: Sun Feb 18, 2024 8:58 pm I see what you mean, it's very juddery, for want of a better phrase.
It's the way it's scripted. Repeat loops , loop via key downs, and move statements are not the way.
SIDEWAYS_With_Game_Loop.oxtstack
(122.43 KiB) Downloaded 24 times
First added globals, you can't expect clean/smooth anything inside of key down events so you have to simply set some values in the keydown and allow the program to proceed and time things in another way.
global bAnimating -- are we animating? Then don't progress the game turns
global playerAnimFrame --- the current frame of animation
global animDelay --- only update animation frames every so many increments of the delay
global animDelayConstant --- the number of increments to wait before changing anim frame

global playerDirection --- either positive or negative 1
global lastPlayerDirection --- are we still going the way we were going?
global lastKeyDown --- is the key that was pressed still held?
global gCurrentTurn --- current turn of the game, just for keeping track that game.loop ran complete
global playerSpeed --- this would modify the pixels per turn the player could move, if they could
openCard now calls init.App which calls init.Globals and init.UI and finally game.validatePlaying
always gotta init the globals
The reset button stuff was moved to init.UI

when you have a loop (ie, send Handler to object in x milliseconds) you always need a way to escape the routine, else you can get runaway program.
game.validatePlaying makes sure the mouseloc is within the window and "browse tool" is chosen.
The mouse thing could be removed and a global for "bPlaying" could be added to toggle via escape key or a screen button, whatever. Tracking the mouse is just an easy way to escape the program while programming it. Even when 15,000 'send in x milliseconds' messages are piled up in the buffer you can put the mouse outside the window, go get coffee any usually have your program done freaking out and waiting for you like an docile obedient monster.

Added a game loop and a sub loop for animation, ie, game doesn't continue until animation is complete.
One 9 frame animation of the wolf is ...uh 9 pixels of motion on the landscape and 27 pixels for the sky.

I had the wolf running around but commented that out (with one line) as it's not necessary , wolf runs, camera is centered on wolf, scenery changes around wolf, like in reality.
Wolf stops moving only when turning, first key press after turn = turn and stop, then it picks up again.

There is still an issue with ramping of speed, like you press key to go, you go real slow, hold down the key and the backlog of messages gets pushed through. It's strange behavior. Oh right, so currently once you start moving, unless you stop by turning followed by key up then you keep running, weeeee. That's one of the reasons I froze the wolf to the center. Wanted to keep testing the animation speed without having to keypress.

Anyway, loops are the key. Note in this stack the loop goes from:
init.app to

game.validatePlaying to

to game.Continue to
to game.Loop which
..increments the animDelay until that variable hits its limit per frame
....turn.animate ---
....turn.updatePositions
.........finally back to game.Validate and round and round it goes.

If you just ping pong between two handlers you get a 'can't find Handler' error. if you send in x seconds between two handlers you can quickly run into recursion limit. Intermediary handler seems to handle this as long as one of the handlers is using a send in x milliseconds delay, else Error- Can't Find Handler!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests