How do I load a game without restarting the music

  • 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?

  • 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'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?

  • 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.

  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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.

  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)