How do I load a game without restarting the music

Get help using Construct 2

Post » Mon Jun 15, 2015 8:03 pm

In older game engines I used, loading a game would not stop the music from playing, so it was easy to check if the sound was already playing and decide whether or not to keep it playing. In Construct 2, it seems as if the music stops when the game loads (which, to be fair, makes a lot of sense), so I can't check if the music is playing or not.

This becomes a problem with my game's checkpoint system- I have a bunch of checkpoints within a level, so I figured it was easiest to save the game and load whenever the player dies (which is often, hence the checkpoints). However, when I do, the music skips back to where it was when I saved, which gets annoying real fast, especially when the player can die only a few seconds after they reach the checkpoint.

So how do I get around this? I can check if the game was just loaded from a save file, and... not play the song then? How would that work? And how should I go to the part of the song that was playing when the player died?
B
5
Posts: 8
Reputation: 241

Post » Mon Jun 15, 2015 10:07 pm

I'm not an expert, but here's a way you could handle what you're doing :

Back when I was making something like what you're trying to make, I would give my checkpoints an instance variable that would depend on how far into the level they were :
-Starting position would be 0
-First checkpoint would be 1
-and so on...

Crossing one would set a global variable (with 0 being its default value) to that particular checkpoint's value, while also negating the effects of those with lower values so that you can't backtrack and stuff.

At the beginning of a layout, the game would check what value was stored in the global variable and spawn the player on the checkpoint sharing that value. Any death would cause the layout to reset which doesn't affect music if I remember correctly.
B
12
S
3
Posts: 33
Reputation: 897

Post » Tue Jun 16, 2015 1:58 am

VonFirflirch wrote:I'm not an expert, but here's a way you could handle what you're doing :

Back when I was making something like what you're trying to make, I would give my checkpoints an instance variable that would depend on how far into the level they were :
-Starting position would be 0
-First checkpoint would be 1
-and so on...

Crossing one would set a global variable (with 0 being its default value) to that particular checkpoint's value, while also negating the effects of those with lower values so that you can't backtrack and stuff.

At the beginning of a layout, the game would check what value was stored in the global variable and spawn the player on the checkpoint sharing that value. Any death would cause the layout to reset which doesn't affect music if I remember correctly.


I thought of that, but would it be practical to save all the enemy positions as well?
B
5
Posts: 8
Reputation: 241

Post » Tue Jun 16, 2015 8:03 am

I was handling that thing in a Castlevania style : layouts were filled with rectangles (tiled backgrounds that I named Zones) of different sizes which would have an influence on the camera scrolling.

On collision with one of these rectangles, the Camera Global Variable would change to fit that Zone's UID (you have to make sure your player can't collide into several zones at once by spacing them, for instance, I had 16 pixels between each zones). Once that's set, another event would go :
"If Camera Global Variable=Zone.UID"
-->"Set scrolling X to Clamp(Player.X, Zone.X+[half of your resolution's width to ensure that you don't see the empty space], Zone.X+Zone.Width-[half of your resolution's width]. For the Y coordinate, just change X to Y and Width to Height.

Now with that out of the way, I would have spawners everywhere I'd want enemies to appear (With a Text variable to decide what enemy spawns, a Zone variable that would be set to the UID of the Zone they're overlapping on start of layout, along with a few others, to have enemies behave differently for example).

On collision with a Zone, a function would be called to have spawners do their thing : spawn enemies (which would also be given a Zone variable, set to the Spawner's own Z.V., when created) and destroy spawned enemies whose Z.V. isn't equal to the global variable anymore, if you avoided them or ran away for example.

I'll try uploading a .capx if it's too confusing to read.
B
12
S
3
Posts: 33
Reputation: 897

Post » Tue Jun 16, 2015 1:08 pm

But the thing is, this is a space shooter, not a platformer. The only locations you actually go to are all within one view- everything else comes to you. So I'm not sure if saving by zone would be particularly effective.

EDIT: I just bit the bullet and made my own save function that puts the player's position, the enemies' position, and the bullets' position into arrays. It's slower, but there shouldn't be more than 50 objects at a time so I think I'm good?
B
5
Posts: 8
Reputation: 241

Post » Wed Jun 17, 2015 7:04 pm

For my platformer i use several global variable

Music_is_playing (to check if a music is actually playing)
Zone x (where x is the zone player get into)

For exemple :

If Music_is playing = 0
Zone = 1

-> play music "blabla"
-> set music_is_playing = 1

if Zone is not = 1
-> stop music "blabla"

maybe it is not optimal but it is efficient.
Check out the demo of my first C2 Game
https://www.scirra.com/arcade/other-gam ... n-demo-482
Follow me @84Gamestudio
B
16
S
5
G
2
Posts: 24
Reputation: 2,816

Post » Wed Jun 17, 2015 8:26 pm

Goomba wrote:For my platformer i use several global variable

Music_is_playing (to check if a music is actually playing)
Zone x (where x is the zone player get into)

For exemple :

If Music_is playing = 0
Zone = 1

-> play music "blabla"
-> set music_is_playing = 1

if Zone is not = 1
-> stop music "blabla"

maybe it is not optimal but it is efficient.


But again, using zones isn't really effective for me, because the player is only in one location, and the enemies come to you.
B
5
Posts: 8
Reputation: 241

Post » Wed Jun 17, 2015 10:39 pm

Check the Audio object's properties : one of the option is Save/Load. I haven't tried but I think setting this to none is probably the way to go.
B
12
S
3
Posts: 33
Reputation: 897

Post » Wed Jun 17, 2015 11:04 pm

VonFirflirch wrote:Check the Audio object's properties : one of the option is Save/Load. I haven't tried but I think setting this to none is probably the way to go.


Oh.
Well that was way easier than it looked. Thanks!
B
5
Posts: 8
Reputation: 241


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests