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
Printable View
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
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();
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.
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 ;)
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.
That's the tutorial I've been using, I just don't know how to implement the switch frames bit into the door.
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?
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 need different music for each map and I don't know how to do that unless it switches frames. How do you do that?
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.
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;
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.
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.
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.
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.Code:function playMusic(id){
music.stop();
music.attachSound(id);
music.start();
}
playMusic("theId")
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:
then when you do the collision with that tile you pass that tile's music to the music function.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;
if collision with tile {
_root.changeMap(tile.newMap)
_root.changeMusic(tile.newMusic)
}
make sense?
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.
I figured it out, thanks for all the help