Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / 2D world, switching 'rooms'

Author
Message
Dale Schultz
2
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 16th Nov 2021 21:31
Is there a 'best practices' approach to switching 'scenes' in the 2D world? By scenes I mean things like an instrument panel, tool box and maybe a data display, and we want the user to be able to flip between them.

Do people create visual objects 'off-screen' and then shift them on screen somehow, or do we delete everything and recreate each scene every time we want to change?

I am sure there are tricks such as:

1- having a background sprite that has a depth such that it obscures items that don't belong in the current screen and adjusting depth values to make things appear (items may still match hit tests though)
2- marking some items invisible and setting current items visible etc...
3- defining a virtual screen larger than the physical screen and somehow panning the virtual screen to display what we want..
4- set the position of unneeded objects off screen and simply reset their positions when needed?
5- ???

I have not come across anything resembling a 'container' yet that could be used to 'hold' a bunch of items and switch their visibility en mass.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 16th Nov 2021 21:36
Quote: "delete everything and recreate each scene every time we want to change"


I would, before each change save to file then switch by deleting everything then loading back up because of memory issues.

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 16th Nov 2021 22:43
Hi Dale (I made sure to read your post, and re-read to make sure, lol)

1, as you said this will mess with hit testing, if anything I would advise against that approach, also point 2. as invisible sprites still register with hit tests.

3. "The Game Factory" and "Multimedia Fusion", was built around this approach, you just have a giant area to work with and pan the view to suit the scene you want to display, personally speaking I thought it was naff, but it works, so its a viable option

4. if the "pop up" scene is A not resource heavy and B in use a lot like an inventory, then yeah, move them off screen but you might run into depth issues with the underlying sprites

5. is well, yeah delete it and recreate it each time you need it, again depending on how resource heavy the "pop-up" is...

personally speaking here, I would off screen them and use this as an opportunity for some "eye candy" and tween it, make the pop-up slightly smaller than the screen so you can still; see what's behind and have a fade sprite and tween the *inventory* in ...

kinda like this

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Dale Schultz
2
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 17th Nov 2021 01:25
thanks,

I am leaning towards option 4, setting the x position of everything, thereby essentially panning everything sideways. That way I can handle events that may occur when out of sight as usual.

I am yet to find out if my app is going to be heavy on resources /slow/ fast. I could skip looking for user input for items that are off screen if it starts getting slow.

Generally the display is not going to have a lot of things happening, one 'scene' will have an image (with a shader) and a special slider, the others, mostly buttons, but there is a TCPIP connection that is being handled in the background too.

I'll do some experimenting.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 17th Nov 2021 01:49
Quote: " I could skip looking for user input for items that are off screen if it starts getting slow."


I would do that anyway, look into "state machines" (basically a select statement, it sounds technical but its not, lol) , they have been discussed many times on the forums, you should only be processing what's visible and active, if not for performance then for bug prevention.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 17th Nov 2021 01:52
You can also use

setvirtualbuttonactive ()

Dale Schultz
2
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 18th Nov 2021 03:32
seems to be working well.

Items that can be set invisible, I simply toggle depending on what scene is active. Other item for which I have not added a visibility property, I just shoot way off and bring them back when needed.

I made a control type that takes a collection of my button types and that operates them in radio button style, so I can switch between any scene as needed.

Thanks

Login to post a reply

Server time is: 2024-03-28 20:58:03
Your offset time is: 2024-03-28 20:58:03