restoring the states when returning to earlier scene
Right now when I go from scene A to scene B and then back to scene A, scene A is completely re-initiated. Is there anyway for me to go back to the states scene A was in when I last left it?
It used to be you have to explicitly call a
reload("scene");
go("scene");
to reinitiate and switch scene, then changed go() to call reload() by default cuz it looks like that's a more often use case, we can either
- go back to having to explicitly call
reload("scene") - come up with a function name for
go()to a scene but not reinitiate
You could also have go(name, reload=True, ...args) although that introduces a breaking change.
Meanwhile, I tried commenting out the reload function and found a bug.
In the level example, if you have a level like this below, where you go to a different scene when you overlap with door "|". When you come back (without reloading), the coins would all fall down and off the screen.
const map = addLevel(
[
" ",
" ",
" ooo ooo ooo ooo ooo ",
" ^+++====+= ====+= ====+= ==== ==== ",
" ",
" ",
" ",
" | ",
" =++=== ",
" ",
" oo ",
" ===== +++ ** ",
"==========++===+=^====+++==========++===+=^====+++==========++===+=^====+++==========++===+=^====+++==========++===+=^====+++==========++===+=^====+++",
],
{
width: 11,
height: 11,
pos: vec2(0, 0),
"+": [sprite("steel"), solid()],
"=": [sprite("grass"), solid()],
"^": [sprite("jumpy"), solid(), "jumpy"],
"|": [sprite("door"), "door"],
"*": [
sprite("spike"),
body(),
area(vec2(0, 6), vec2(11, 11)),
"hurt",
],
o: [sprite("coin"), body(), "coin"],
}
);
Before going to the door

After coming back. You can see the coins falling down (sorry for the bad cropping - had to take it very quickly since the coins would fall off the screen completely)

hmm, do you have the full code that I can try?
hmm, do you have the full code that I can try?
sorry I can't find it anymore, but you should be able to reproduce it just from what I have above. Either way, this bug doesn't affect me personally anymore for now - I suppose it's just something to keep in the back of the head as the project moves forward.
Btw, I loooove Kaboom. I really feel like I can get building within 5 min of playing with the APIs (I have no game dev experience, only web dev). Great work!
Closed.
For sending data through scenes can be used:
kaboom()
scene("1", () => {
let data = {
life: 300,
}
go("2", data)
})
scene("2", (data) => {
debug.log(data.life)
})
go("1")
And stay() for mantain objects in scene changes