A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: [RESOLVED] [F5] Question about Doors in Tile Based games

  1. #1
    Member
    Join Date
    Aug 2006
    Posts
    39

    [RESOLVED] [F5] Question about Doors in Tile Based games

    I'm making a tile based game and I was wondering, how do you tell it if the character goes onto a certain tile go to and stop at the next frame? Also, how do you tell it to stop the music from the last frame when you go to the next one?

    Thanks
    Tears have turned from sweet to sour
    And hours to days
    You're hiding yourself away from our cruel world's embrace
    And as your days turn to weeks
    You will cry yourself to sleep
    In the cage

    -The Cage by HIM

  2. #2
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    I don't know specifically, but if you have a special tile that marks doors then do a hitTest; a little sloppy but it should work. For the sound you have two options. If the sound is located in a frame you can use stopAllSounds(); if you are controlling the sound dynamically then you just use my_sound.stop();
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  3. #3
    Member
    Join Date
    Aug 2006
    Posts
    39
    I can't use stop all sounds because it's switching to another frame that also has sound, I'm just getting them jumbled together.

    I'm not sure how to use a hitTest. Is there a way to tell it "when you go through a certain door/the new map is a certain map, go to this tile"? I'm trying to do

    if (newMap==3) {
    gotoAndStop (4);
    }

    But it doesn't seem to want to work.
    Last edited by Pi_Mastuh; 07-20-2007 at 05:11 PM.
    Tears have turned from sweet to sour
    And hours to days
    You're hiding yourself away from our cruel world's embrace
    And as your days turn to weeks
    You will cry yourself to sleep
    In the cage

    -The Cage by HIM

  4. #4
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    You could use an invisible mc at that door that the Character will touch, triggering the gotoAndPlay bit. Check HitTest in the help, aint too complicate, even I can understand it
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

  5. #5
    Senior Member
    Join Date
    Nov 2005
    Posts
    192
    http://www.tonypa.pri.ee/tbw/start.html

    The application of doors in his tutorial is somewhat limited, if you have many doors, you need many prototypes. However that's the basic idea. Once you get it working you can find ways to make it more flexible.

  6. #6
    Member
    Join Date
    Aug 2006
    Posts
    39
    That's the tutorial I've been using, I just don't know how to implement the switch frames bit into the door.
    Tears have turned from sweet to sour
    And hours to days
    You're hiding yourself away from our cruel world's embrace
    And as your days turn to weeks
    You will cry yourself to sleep
    In the cage

    -The Cage by HIM

  7. #7
    Member
    Join Date
    Aug 2006
    Posts
    39
    I've tried

    if(char, hittest(game.Tile37)){
    _root.gotoAndStop(4);
    }

    as well as

    if (char.x == 0 and char.y == 14) { gotoandStop (4); }

    But neither want to work. Any ideas why?
    Tears have turned from sweet to sour
    And hours to days
    You're hiding yourself away from our cruel world's embrace
    And as your days turn to weeks
    You will cry yourself to sleep
    In the cage

    -The Cage by HIM

  8. #8
    Feeling adventurous? T1ger's Avatar
    Join Date
    Mar 2004
    Posts
    850
    You shouldnt use frames for different levels, but just reload the map and relocate the player.. you may not know how to script that, and because of that you should read up some more on tonypa's tutorials, and then try a bit..
    I don't have a photograph, but you can have my footprints. They're upstairs in my socks.

  9. #9
    Member
    Join Date
    Aug 2006
    Posts
    39
    I need different music for each map and I don't know how to do that unless it switches frames. How do you do that?
    Tears have turned from sweet to sour
    And hours to days
    You're hiding yourself away from our cruel world's embrace
    And as your days turn to weeks
    You will cry yourself to sleep
    In the cage

    -The Cage by HIM

  10. #10
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    put your music in the library then attach it to a sound object

    var music = new Sound() //do this once

    //do this when you want to change the music

    music.stop()
    music.attachSound("libraryId")
    music.start()

    make sure the sound in the library has "export for actionscript" checked. And replace "libraryId" with the linkage id of your sound.

    As for changing levels, do what Tiger said, if you're following tony's tuts then he should already tell you how to do that.
    lather yourself up with soap - soap arcade

  11. #11
    Member
    Join Date
    Aug 2006
    Posts
    39
    Where do I put var music = new Sound() //do this once? And where exactly would I put the 2nd part? Would I put it in

    game.Doors4 = function (newMap, newcharx, newchary) { this.newmap = newMap;this.newcharx = newcharx;this.newchary = newchary;};
    game.Doors4.prototype.walkable = true;
    game.Doors4.prototype.frame = 61;
    game.Doors4.prototype.door = true;
    Tears have turned from sweet to sour
    And hours to days
    You're hiding yourself away from our cruel world's embrace
    And as your days turn to weeks
    You will cry yourself to sleep
    In the cage

    -The Cage by HIM

  12. #12
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    You can put it wherever you want.

    But the most likely place is the _root. I would make a function for the second part and then call that function when i need to run it.

    function playMusic(){

    music.stop()
    music.attachSound("libraryId")
    music.start()
    }

    _root.playMusic()

    it really looks as if you don't understand much/everything of what you're doing. Have you read the help files in flash? like the introduction to action script 2.0. I suggest you read it. Not knowing where to put a function is a little worrying when you're attempting to build a tile based game, you're going to come across many little hurdles if you can't master that.
    lather yourself up with soap - soap arcade

  13. #13
    Member
    Join Date
    Aug 2006
    Posts
    39
    I just don't know where to call the function because the script that tells it to switch maps is generic and I need different music for different maps.
    Tears have turned from sweet to sour
    And hours to days
    You're hiding yourself away from our cruel world's embrace
    And as your days turn to weeks
    You will cry yourself to sleep
    In the cage

    -The Cage by HIM

  14. #14
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    thats exactly what your function should be like, try to be more generic. Why create frames for individual music? thats just a useless amount of work.
    Code:
    function playMusic(id){
    
    music.stop();
    music.attachSound(id);
    music.start();
    }
    
    playMusic("theId")
    I think i'm finally understanding your main problem. Your generic map function can't be so generic in that it doesn't know which map its loading correct? So if your passing a variable to the newMap function which tells it which map to load or which frame to goto, you do the same with the sound function.

    Just a guess, but somewhere in your code you must have a tile which tells your script where to go (what map to load)? lets say you have it in the door prototype you posted before, you would add:
    Code:
    game.Doors4 = function (newMap, newcharx, newchary, newMusic) { this.newmap = newMap;
    this.newcharx = newcharx;
    this.newchary = newchary; 
    this.newMusic = newMusic;
    };
    game.Doors4.prototype.walkable = true;
    game.Doors4.prototype.frame = 61;
    game.Doors4.prototype.door = true;
    then when you do the collision with that tile you pass that tile's music to the music function.

    if collision with tile {

    _root.changeMap(tile.newMap)
    _root.changeMusic(tile.newMusic)

    }

    make sense?
    Last edited by mr_malee; 07-23-2007 at 01:06 AM.
    lather yourself up with soap - soap arcade

  15. #15
    Member
    Join Date
    Aug 2006
    Posts
    39
    Ah, that makes sense.

    I've got it to connect to the function and it stops the music but it still isn't figuring out which to load, it just stops.
    Last edited by Pi_Mastuh; 07-23-2007 at 01:46 AM.
    Tears have turned from sweet to sour
    And hours to days
    You're hiding yourself away from our cruel world's embrace
    And as your days turn to weeks
    You will cry yourself to sleep
    In the cage

    -The Cage by HIM

  16. #16
    Member
    Join Date
    Aug 2006
    Posts
    39
    I figured it out, thanks for all the help
    Tears have turned from sweet to sour
    And hours to days
    You're hiding yourself away from our cruel world's embrace
    And as your days turn to weeks
    You will cry yourself to sleep
    In the cage

    -The Cage by HIM

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