Making the player spawn at a different location after going between scenes.

keflynkeflyn Member Posts: 29
edited November -1 in Working with GS (Mac)
Hello,

Sorry if this has been asked before, I can't find the search function on this website.

In my game the player can go in and out of buildings, I've got it so they are able to do so but when they come out of a building, they spawn at the start of the game again. I would like to know how to make it so the players spawns just outside the building they just entered?

Thanks in advance.

Comments

  • gazjmgazjm Member Posts: 578
    have 2 game attributes called lastX and lastY

    When your enter a building save the players x and y location to the relevant last attribute.

    When reentering the scene, have the player spawn at lastX and lastY values.

    Something like that should work!
  • keflynkeflyn Member Posts: 29
    What type of attribute should they be? Real? How do you have the players x and y locations? Sorry, I'm very new to gamesalad.

    Thanks.
  • gazjmgazjm Member Posts: 578
    yes, choose a real attribute for them.

    You will need to have a rule in your player which just before the scene changes saves the values.

    use a change attribute behaviour and save player.x to lastX and player.y to lastY

    If your in the player actor it will be self.x and self.y that need saving.
  • keflynkeflyn Member Posts: 29
    That didn't work, what did I do wrong?

    Got two attributes like you suggest, then inside the player actor I have this;

    Rule

    Actor receives event - overlaps or collides - actor of type - jump-2-apartment

    - Change attribute - self.positionX to game.lastX
    - Change attribute - self.positionY to game.lastY

    Thanks again.
  • gazjmgazjm Member Posts: 578
    I think you've saved the wrong way round, you need to change attribute game.lastX to self.positionx and the same for y.

    In your spawn rule, spawn at lastX and lastY.
  • keflynkeflyn Member Posts: 29
    Spawn rule? Is that the rule I listed above?
  • keflynkeflyn Member Posts: 29
    Any more help on this? I've been adding spawns behaviors and nothing seems to be working?
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    it should be like this. Have you 2 real attribute lastx and lasy

    whenever you want to change scenes-
    change attribute lastx to self position x
    change attribute lasty to self poision y
    then a timer after 0.1 second run to completion checked,

    change scene

    then at the start of the scene when you go back to it,

    change attribute self position x to last x
    change attribute self position y to last y
  • keflynkeflyn Member Posts: 29
    Do I put the behaviors in the player? or the actors that are making the scene change?
  • keflynkeflyn Member Posts: 29
    I put them inside the rules where the character is jumping between scenes but it doesn't seem to be working still? I'm really sorry if I'm sound stupid, it's getting late here.
  • keflynkeflyn Member Posts: 29
    I still can't get this to work or figure out why it's working. Here is what I've done, maybe you can see what I've done wrong?

    I have 3 actors, my playable character, an actor that sends my character to the next level(jump-2-apartment) and another actor that sends them back to the first level. (jump-2-street)

    in my player I have this rule set up;

    Actor receives event - overlaps or collides - actor of type - jump-2-
    apartment

    change attribute
    change attribute game.lastx to self.positionx
    change attribute game.lasty to self.positiony
    timer every 0.1second
    Go to Scene - "Apartment"

    Actor receives event - overlaps or collides - actor of type - jump-2-street

    change attribute
    change attribute self.positionx to game.lastx
    change attribute self.positiony to game.lasty
    Go to Scene - "Apartment-street"

    *Note* All behavior is in player actor non in the scene change actors.

    That is all the behavior for the scene changes, where have I gone wrong?

    Thanks again and sorry for being so stupid with this.
  • gazjmgazjm Member Posts: 578
    you don't need to put the change lastX and Y rules in actor for returning back to the street, that is overwriting the location saved when you entered the building.

    What you need is, in your playable actor on the street scene, a rule which as soon as it loads changes its self.x and self.y position to lastx and lastY.

    The only thing is, at the start of a new game you want the player to start in the starting point, not the lastX and lastY. To do this, have a rule in your start button on the titlescreen which changes lastX and lastY to the position you want the player to start.
  • keflynkeflyn Member Posts: 29
    never mind, got it to work, just the problem now of working out the start x and y position argh.

    Also, since my character is spawning at the actor that sends it to the next scene, my scene just changes instantly when going back to the starting scene?

    on top of that problem, there is now a problem with my light, it's not following with my player up and down anymore, just left and right and is not spawn above my player either, it's spawning at the bottom?
Sign In or Register to comment.