Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene transitions (pushing popping multiple scenes at once) #16

Open
joetsoi opened this issue Jan 23, 2019 · 4 comments
Open

Scene transitions (pushing popping multiple scenes at once) #16

joetsoi opened this issue Jan 23, 2019 · 4 comments

Comments

@joetsoi
Copy link
Contributor

joetsoi commented Jan 23, 2019

What's a sensible way of handling transitions?

I added a FadeIn/FadeOut Scene, the problem is that once you pop the scene, the scene underneath is drawn for a frame before that is popped, so a fade to black would suddenly flicker once before being popped off.

I solved this by adding Push/PopMultiple but I'm unsure whether this is a good idea? see master...joetsoi:push-multiple

@icefoxen
Copy link
Contributor

Sorry for the delay in getting back to you.

The way I did transitions is basically the same as yours, but IIRC I used SceneSwitch::Replace instead of popping and then pushing, so it didn't show the previous scene. But, having the scenes be a strict stack is kinda restrictive; I'm not sure whether it's a good idea any more than you are. Taking a look at Amethyst's State isn't a terrible guideline, since it's basically the same concept.

Also if you want to contribute your FadeIn/FadeOut code I'd be happy to merge it. Mine is massively out of date by now.

@joetsoi joetsoi closed this as completed Jan 26, 2019
@joetsoi
Copy link
Contributor Author

joetsoi commented Jan 27, 2019

no problem on the delay, not expecting instant replies. The problem I ran into with replace is that if I push a fadeout scene and emit a Replace I'd leave the scene I was fading out on the stack.

[Combat]
// push a fadeout, this draws our combat scene underneath and fadesout.
[Combat, FadeOut]
// fade out is now complete, so fadeout does a replace, say back to the main menu
[Combat, MainMenu]

I had a quick read around about push down automatas and there's some definitions allow pushing multiple and popping multple can be simulate by epsilon transitions, so there's nothing wrong with them in principle. I'm just trying to figure out the "best way" ™️

@icefoxen icefoxen reopened this Jan 27, 2019
@icefoxen
Copy link
Contributor

icefoxen commented Mar 13, 2019

Heh, now that I think back, I had this exact problem and I think I resolved it by having my FadeOut scene be a Replace and actually consuming the old scene and drawing it as necessary. So you'd have:

[Combat]
// Replace a fadeout, the fadeout gets ownership of the old scene that got popped, 
// and draws it on its own
[FadeOut (containing old Combat scene)]
// Fadeout replaces itself with main menu
[MainMenu]

It's a bit of a hack, but it's such a neat hack, right? Pushing and popping multiple scenes might honestly be simpler. XD I don't know any better than you in this case.

@joetsoi
Copy link
Contributor Author

joetsoi commented Apr 17, 2020

Finally found some time for this. I've run into a problem if I try to replace the current scene and give fade out owenrship of the current scene that I'm calling update https://github.com/ggez/ggez-goodies/blob/master/src/scene.rs#L32

so if I try to emit a replace

fn update(&mut self, mut game: &mut Game, ctx: &mut Context) -> FSceneSwitch {
     // if self.done {
     SceneSwitch::Replace(self)
}

which isn't possible, since I have a mutable reference to self. So I could clone the scene, but this seems quite wasteful, especially if there is a lot of state in the scene.

The other way I looked into would be to Pop, but there's nowhere to consume that popped scene as it's just discarded https://github.com/ggez/ggez-goodies/blob/master/src/scene.rs#L133

This isn't a problem for a fade in, as you're fading into a new scene.

I was also worried about the static lifetimein https://github.com/ggez/ggez-goodies/blob/master/src/scene.rs#L52 , but that might be completely unfounded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants