A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Leaving the 'scene' and coming back without everything being reset (eg. rooms).

  1. #1
    Member
    Join Date
    Apr 2007
    Posts
    75

    Leaving the 'scene' and coming back without everything being reset (eg. rooms).

    Hey everyone,

    I've been wondering something and for the first time in a long while I had no idea how to find info on this, hence this post.

    I'm currently making a very simple 2D side-scrolling platformer. Along the way the main character will be slaying zombies and destroying some obstacles (hence my ubercool working title: Zombie Slayer!). What I would like is for the character to be able to enter a building (by pressing the up arrow) and leave it again. Now here's my problem area: What would be considered best practice for ensuring that when the player returns to the main setting (outside), the zombies that were killed are still dead and the obstacles that were destroyed are still kapüt?

    I was initially thinking of just throwing the entire inside of the building onto a new frame in the Main Timeline, and using the Document Class (which I haven't used up till now) to keep track of who or what was killed/ destroyed. Then after going back outside (ie. frame 1), have the Document Class kill what should be dead upon loading.

    Another idea of mine (which is sort of a dirty hack I guess) was to just build the inside of the building above the view (say, 700px), and switch it out with the outside stage by messing with the Y-coordinates (outside.y += 700; inside.y += 700; //and vice versa).

    I'm not looking for specific help with the programming, just some thoughts on what the best way to tackle this is. =)

    Thanks in advance,
    Patrick
    Last edited by senshi sentou; 05-05-2011 at 06:39 PM.

  2. #2
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    838
    It's a good idea to store the enemy data in an array similar to this concept.
    Actionscript Code:
    room1Data:Array = ["alive","dead","alive","dead","dead"];
    and perhaps store all stages in a larger array..
    Actionscript Code:
    sceneArray = [ room1Data, room2Data, room3Data, room4Data];
    And when you load room1, you check room1array to see if the enemies will be alive or not.

    Actionscript Code:
    //check enemy1
    if (room1Data[0] == "dead") {
    // kill enemy 1
    }
    if (room1Data[1] == "dead") {
    // kill enemy 2
    }
    if (room1Data[2] == "dead") {
    // kill enemy 3
    }

    If you're moving around to different frames, keep in mind that if you create all of these variables on a frame in the timeline, go to a different frame, and then go back, you'll reset all of the variables.

    If you need some clarification ask away, and I'm sure someone else can help if I can't.

  3. #3
    Member
    Join Date
    Apr 2007
    Posts
    75
    Hey, thanks for your response! +1 for the array approach then. =) That example of yours looks good, but perhaps an associative array would be even cleaner?
    Code:
    var zombieData = {room1:[true, true, false, true],
    room2:[false,false,fase,true]}
    -Patrick

    EDIT: Nvm, this is essentially what you are doing. It's too late for me to be reading and replying to this. =P Sorry!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center