Sidescrolling Platformer — Part 8 — Multiple Levels

Here’s the post you’ve all been waiting for… how to connect multiple levels in your platformer!

Try out this demo. Press the down arrow key upon opening the door to warp to the next level:

After adding the door and key last time, the next step is to make the door lead to the next level. “How?”, you might ask… just read on to see the magic unfold.

The Plan

Before we dive head-first into things, let’s take a moment to plan out the structure of the platformer. There are tons of different ways to accomplish what we are trying to achieve — some more complicated than others. I’m going to stick with the simplest solution I’ve come up with so far.

We are going to use multiple frames inside the background object to hold different levels.

Last tutorial, we were able to give the locked door multiple image states by using the frames on its animation timeline. We are essentially doing the same thing with each of the layers of the background.

  1. When the player opens the door, he can press the down arrow key to enter the door and proceed to the next level.
  2. To switch levels, we will gotoAndStop() to the appropriate frames inside the back.visuals container-object, the back.collisions container object, and also the back.other container-object, which we still need to create (this will hold the door and key).
  3. Then we will reset the scrollX and scrollY variables to move the player to the beginning of the next level.
  4. Finally, we will reset any level-specific variables and settings, such as the doorOpen and keyCollected variables.

Editing the Background Object

It seems that we’ve been spending most of each recent tutorial just setting up the visual components of the game… this isn’t true for most games, but because we are creating an “art-based” platformer, there is really no way around it. And once again, we need to go back to the drawing board and modify the background.

Creating the Container for the Other Background Objects

First, we need to update the “Other” layer from the last tutorial, in which we placed the key and the door. In order for the multiple-level code to work, we are going to “nest” the key and the door inside a container Movie Clip, just like we did with the visuals layer, and the collisions layer. So after double-clicking on the main background object, select everything on the “Other” layer (which should just be the lockedDoor and the doorKey objects), and then convert them to a new Movie Clip (Modify –> Convert to Symbol). I named mine “Background Other Objects Container”. Set its registration to the lower left, and gave it the instance name “other“.

(One little detail you might notice from the above image is that I set the x and y location of the object container to be (0,0), and then adjusted the relative positions of the door and the key to keep them in the correct locations.)

That’s all we need to do right now with these objects.

Creating Level Two

Creating level two involves editing each of the container objects inside the main background, and adding a second frame to their timelines. We can draw the outline of the platforms in 2nd frame of the Background Collisions Container. We can draw the fancy visuals inside the 2nd frame of the Background Visuals Container. And we can move around the door and the key to their new positions in the 2nd frame of the Background Other Objects Container.

Let’s start with the Collisions Layer, since it gives us a guideline for what the other two layers should look like. Edit the collisions object by double-clicking on it. It’s probably hidden behind the visuals layer, so you might need to “lock” the visuals layer in order to click on the collisions container (You can lock/unlock a layer by clicking the little lock icon next to the layer name on the timeline — while a layer is locked, it cannot be modified).

Here is what my Frame 1 looks like:

 After adding a new keyframe (Insert –> Timeline –> Keyframe), switching to it, deleting everything besides the main floor and walls, and drawing new platforms, here is my Frame 2:

I didn’t put too much thought into the level design. Feel free to make your levels cooler than this ;)

As you can see from the above screenshot, I also created another layer, called “actions“. Just like the locked door in the last tutorial, we need to stop() the Movie Clip from automatically animating. So click on Frame 1 of the actions layer, and type stop(); into line 1 of the Actions panel.

The collision layer is now ready, but we need to update the visuals layer to match up with the new platforms. To make sure that both layers line up correctly, select everything you just drew in the collisions layer (Edit –> Select All or Command+A), and Copy it. Go back to the main background Movie Clip, and now edit the Background Visuals Container. Insert a new keyframe, and delete anything which you don’t wish to reuse in level 2. Next, here’s the trick I used to make sure everything lines up: Add a new layer, and drag it to the bottom of the stack of layers, so that anything you draw on it will show up beneath the other layers. I named it “platform guide”. Finally, use Edit –> Paste in Place (or Command + Shift + V ), to paste the level you just drew in the collisions container-object. We will delete this layer at the end, but for now it serves as a guide to follow as we draw the fancy visuals in the other layers.

It’s time to create the stunning visuals for level 2! I just repeated the steps I used to draw Level 1. I’ll spare you the grisly, step-by-step details of the process behind my art — if you need help, refer back to Part 6.

Here is my final product, complete with grass and palm trees which I copied from the last frame:

Remember to delete the “platform guide” layer at the end. Then, using the same method with which you stopped the animation of the collisions container, add an “actions” layer to the visuals container and stop(); the animation at frame 1.

We’re almost done!

Return to the main background object, and edit the Background Other Objects Container (which we created earlier this tutorial). This one is easy. Once you add a keyframe to the timeline, all you need to do is drag the door and the key into your desired positions, so that frame 2 matches up with frame 2 of the other layers. In order to find the right location for the door and the key, you’ll probably need to use the same process of adding a “platform guide” layer, and using Paste in Place to match everything up. When you are done moving the door and the key, delete the “platform guide” layer, and once again add an “actions” layer with a stop(); command on frame 1.

It might look like random placement after deleting the guide layer, but this is what my Background Other Objects Container looks like on frame 2.

Code Time!

OK, OK, hopefully I didn’t bore you with all that visual editing stuff. If you’re like me, you’re ready to jump into the code! After all, it’s the most fun part!

In case you’ve forgotten, here is the plan we outlined at the start of the tutorial:

  1. When the player opens the door, he can press the down arrow key to enter the door and proceed to the next level.
  2. To switch levels, we will gotoAndStop() to the appropriate frames inside the back.visuals container-object, the back.collisions container object, and also the back.other container-object.
  3. Then we will reset the scrollX and scrollY variables to move the player to the beginning of the next level.
  4. Finally, we will reset any level-specific variables and settings, such as the doorOpen and keyCollected variables.

Let’s start with Step 1, and work our way through.

Return to the frame 1 of the main timeline — where the bulk of our code is written. A long time ago, we created a function called keyDownHandler“, which is activated any time a key is pressed. This is the logical place to work with step 1.

Inside this function, we actually already created a conditional which activates if the down arrow key was pressed — how convenient! :-)

Modify this conditional inside the keyDownHandler function, to include the following:

} else if(e.keyCode == Keyboard.DOWN){
     downPressed = true;
     if(doorOpen && player.hitTestObject(back.other.lockedDoor)){
          //proceed to the next level if the player is touching an open door
          nextLevel();
     }
}

The double “&& signs” just mean AND. The conditional will only work if both of the conditions are true. On a side note, you can use double vertical bars “|| signs” to mean OR (you can type a vertical bar by holding Shift and pressing the backslash \ keyboard key).

Simple enough. But we still need to create the nextLevel() function.

Before we create this function, quickly declare one more variable at the top of the program: the currentLevel, which will be an integer that keeps track of which level the player is currently on.

var currentLevel:int = 1;

I made the nextLevel() function be pretty general, so that we can use it later on to add more and more levels without getting too complicated. Create this function somewhere in your program — perhaps beneath the loop, and just above the keyHandlers.


function nextLevel():void{
     currentLevel++;
     trace("Next Level: " + currentLevel);
     if(currentLevel == 2){
          gotoLevel2();
     }
}

As you can see, all this function does is add 1 to the current level, and then call another function to handle the specifics of setting up that level. By breaking the functions apart into small steps, I am able to keep my program more readable, dynamic, and organized.

Continuing this chain of logic, here is gotoLevel2(), the “meat” of this tutorial’s code.


function gotoLevel2():void{
     back.other.gotoAndStop(2); //updates door and key
     back.visuals.gotoAndStop(2); //updates the visuals
     back.collisions.gotoAndStop(2); //updates the collisions
     scrollX = 0; //resets the player's x position in the new level
     scrollY = 500; //resets the player's y position in the new level
     keyCollected = false; //resets the keyCollected variable
     back.other.doorKey.visible = true; //makes the key visible again
     doorOpen = false; //resets the doorOpen variable
     back.other.lockedDoor.gotoAndStop(1); //makes the door return to its locked image
}

That’s some solid actionscript! The bulk of this function should be pretty predictable. We gotoAndStop() onto the new frames of each of the container-objects in the background, which we painstakingly created today. But if we only did that, the player would start the level floating at the position with which he ended level 1. So we also reset the scrollX and scrollY values. I used 0 and 500 because they work for my level. Maybe they work for yours as well, but maybe they don’t — experiment with different values if you want the player to start at different points in each of your levels. Finally, we took additional steps to reset the door and the key so that we can collect them again in level 2 before proceeding to level 3.

It seems like switching between levels should be such a monumental task. But once you have the backgrounds drawn, it really only takes a little bit of code to make everything work. Your game should be up and running!

Test it out

You might want the source file for this one: here.

Also, in case you can’t open the Flash Professional CS5.5 file, I compiled a complete PDF copy of the source code: here.

Hopefully this tutorial has gotten you well on you way to creating to the next revolutionary platformer game! Stay posted for additional tutorials — I will be adding more and more features as time goes on.

Each of these tutorials takes many hours to produce, which makes it difficult for me to publish them on as frequent a basis as I would like to. So if you want to stay up to date on the latest tutorials, I recommend subscribing to the RSS Feed, or perhaps even better, to the email list. You can receive email updates whenever a new tutorial is posted by using the Follow tool, or the sign-up widget on this site’s sidebar.

I appreciate all that you do to help support this site and spread the word; I do this completely for free, and its great to know that my readers find these tutorials useful :-)

I’ll try to post the next tutorial within the next two weeks — it will explain an efficient way to add animations to the player’s movements.

– Ben Reynolds

About these ads

57 comments on “Sidescrolling Platformer — Part 8 — Multiple Levels

  1. Hey Ben,

    I just wanted to say thank you from one designer to another, because I’m more suited with artwork than coding and I’m trying very hard to get a game design started to a point where I feel it’s suitable enough to blog about. Your post was really informative and helpful, considering I don’t know much about the coding aspect of gaming yet. I’m trying to teach myself, but at the moment I’m using programs like GameSalad and GameMaker to practice my skills.

    Anyways – just wanted to say thank you from one artist to a fellow gamer. Thank you for the detailed tutorials. They really helped me understand the process of coding Flash games better. Do you have any flash games you’ve finished on here?

    • Ben Reynolds says:

      Hi there, sorry I never got back to you sooner. You’re welcome for the tutorials — I’m so glad they have been helpful for you! As far as my own games, none of them are posted on this particular site, but I do have a few elsewhere on the internet. None of these are very recent (they are all 1-2 years old, and therefore quite as good as my current games, which aren’t quite finished enough to upload). But you can find a few here: http://www.mochigames.com/developer/Benolds/

  2. Hi Ben, I have a suggestion for you, you should add a door in the starting of level 2, so that it makes sense that you are travelling by door.

    • Ben Reynolds says:

      Thanks Palash, that’s actually a very good idea! I think for the sake of simplicity, I’ll leave my tutorial how it is, but if this were a game that I was going to publish, I’d definitely add the door.

  3. birdjames9 says:

    Hi Ben, first things first, you are a life saver your tutorials helped me so much so thank you for it. I have an issue though, when I try and pass through the door to the next level from my first one it does not let me, an error comes up saying that something is undefined but as far as I can tell everything is defined :S

    Its not quite the same concept as yours, but when the player goes through to the next level I just want it to gotoAndStop() on a frame on my main timeline so I have not included the currentLevel variable because I don’t think its necessary, what do you thinks going on?

    Thanks
    James

    • kvakk0 says:

      Hello, birdjames, I have learned that some variables that seems unnecessary, may really be vital to making a program work.

      Here is a tip, if you are using CS5, set your program to play as an AIR program, because AIR gives you better error messages(in the output) than flash-player.

      If you are using an earlier version of FLASH pro(I don’t know when AIR was added), try to search google, to find a way to install AIR on your FLASH-program.

      if that still not helping, ask Ben in more details, or send me an email with your code(need the challenge).

      L.E. Grambo

      http://www.grambogames.net

      PS: I give you my email only if you need it

      • birdjames9 says:

        Hi kcakk0, I genuinely don’t think that I need the variables, although I’ll give it a try with everything included, it can’t hurt!
        What is your email I think I might need it at some point.
        Heres a blog of the project, its for my final year project so we had to keep a live blog of it…

        monkeyprogressingnicely.blogspot.com

        James

  4. birdjames9 says:

    Having some trouble with the second level of mine now, the coins I have made which take the place of the keys don’t respond when the character comes into contact, but I have used exactly the same technique on the other page…
    Can send you the code if you need it but its been coming up with error 2007..

    • Ben Reynolds says:

      I did a quick search on error 2007 it looks like one of your parameters you are using is null. Was there anything in the first level that you were checking a hit-test for, that no longer exists in the second level? Did you forget to give something an instance name? If you are still checking for something that was in level 1 only, you either need to add that object to level 2, or stop the program from checking it if the level is not 1 anymore.

      I’m not sure if this is your problem — just a guess as to what might be going wrong.

      • birdjames9 says:

        I have changed the instance of the lockedDoor to lockedDoor2 in level 2 and added the conditional that all keys on level two need to be collected before that door can open, but it just seems to be opening anyway even though all those keys haven’t been collected. Its a strange one I’ve tried keeping the same instance etc but its just coming up with the same error or not working at all…
        I have been using the same movieClip for the door, but changing the instance name on level 2 do you think that might be the problem? Maybe if I use a different movieClip and act completely separate from level 1 it might work..
        How would I stop it from checking if it is in level 1? just change it to false?
        Thanks

        • birdjames9 says:

          Thanks for the tutorial and the help Ben! I finished the project here is the final game…

          newmedia.leeds.ac.uk/ug09/cs09jab/Index/Monkey.swf

          Thanks again,
          James

          • Ben Reynolds says:

            Wow, that’s pretty impressive! I love how you used the game to teach about the rainforest — and nice artwork, too :-)

          • Joel says:

            Thats really good. How did you go about getting the pop up window to appear with the game paused. And the option to close it. I have been trying to find out how to do that

          • birdjames9 says:

            I made a function called pauseGame() which was called whenever a player clicked pause or collected one of the keys (the coins) which basically turned off all the eventListeners which made the character or the background move so the keys did nothing. Then I linked the unPauseGame() function to whichever exit button I had which reactivated those eventListeners! Took a lot of figuring out but heres the code;

            function pauseGame()
            {
            leftPressed = false;
            downPressed = false;
            upPressed = false;
            rightPressed = false;
            xSpeed = 0;
            mcMonkeyWalk.stop();
            stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
            stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
            stage.removeEventListener(Event.ENTER_FRAME, loop);
            }

            function unpauseGame()
            {
            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
            stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
            stage.addEventListener(Event.ENTER_FRAME, loop);
            }

            As for getting the menu screen up I made a movie clip which contained the quality buttons etc, and made it invisible (menuScreen.visible = false;) and then made it visible = true; when I needed to and vise versa!

            Hope that helped let me know if you need help

            James

          • Joel says:

            Mate thanks for that code, worked really well. Very clever stuff. Such a relief to see that working.

          • Joel says:

            Hey i got one more question now. It works great, better than i thought. But the pop up is a movie clip and I dont want it to play till its visable. I have tried the stop(); on the animation itself, and the instance name which is bossDragon i tried on the main script bossDragon.stop(); But it just keeps playing in the background, so when it finally turns visable the animation is over.

          • birdjames9 says:

            ok maybe you could removeChild(your movieclip) when you need it to disappear? Or within your movieClip you could put a blank keyFrame at the start and stop(); in there? then stop(); at the very end of the movieClip…

            in your main code you could put bossDragon.gotoAndPlay(2); when it needs to appear instead of using the visible/invisible trick?
            Send me your code if you need more help

          • Joel says:

            Hey I put the blank keyfram in with a start button and it seems to work great. Once again thankyou for your help. This is the 1st time I have attempted something like this and its great to have help.

          • birdjames9 says:

            no problem! glad to help

  5. Joel says:

    Hey thanks for the great tutorials. Really helping me with a project i am working on for uni. Just got a bit of code that it stuffing me up with trying to go to level 3. If anyone could offer some assistance I would be very happy, This here plays fine, but it replays level 2 when i want to go to 3. I believe it has something to do with the variable currentLevel not changing. Not sure though.

    var currentLevel:int = 1;

    function nextLevel():void{
    currentLevel++;
    trace(“Next Level: ” + currentLevel);
    if(currentLevel == 2){
    gotoLevel2();
    }
    else if(currentLevel == 3){
    gotoLevel3();
    }
    }
    function gotoLevel2():void{
    back.other.gotoAndStop(2); //updates door and key
    back.collisions.gotoAndStop(2); //updates the collisions
    scrollX = 0; //resets the player’s x position in the new level
    scrollY = 500; //resets the player’s y position in the new level
    keyCollected = false; //resets the keyCollected variable
    back.other.doorKey.visible = true; //makes the key visible again
    back.other.wrongKey1.visible = true;
    back.other.wrongKey2.visible = true;
    back.other.wrongKey3.visible = true;
    doorOpen = false; //resets the doorOpen variable
    back.other.lockedDoor.gotoAndStop(1); //makes the door return to its locked image
    }

    function gotoLevel3():void{
    back.other.gotoAndStop(2); //updates door and key
    back.collisions.gotoAndStop(2); //updates the collisions
    scrollX = 0; //resets the player’s x position in the new level
    scrollY = 500; //resets the player’s y position in the new level
    keyCollected = false; //resets the keyCollected variable
    back.other.doorKey.visible = true; //makes the key visible again
    back.other.wrongKey1.visible = true;
    back.other.wrongKey2.visible = true;
    back.other.wrongKey3.visible = true;
    doorOpen = false; //resets the doorOpen variable
    back.other.lockedDoor.gotoAndStop(1); //makes the door return to its locked image
    }

    • Ben Reynolds says:

      Hi Joel,
      I’m not sure, but your problem might be from these lines:

      function gotoLevel3():void{
      back.other.gotoAndStop(2); //updates door and key
      back.collisions.gotoAndStop(2); //updates the collisions

      ….

      I think you should replace the gotoAndStop(2) with gotoAndStop(3)

      Let me know if this works,
      Ben Reynolds

      • Joel says:

        wow thats awesome. Thats all it was. Unreal. Thanks heaps for this tutorial and all the help.

        • Ben Reynolds says:

          Awesome — I’m glad it worked :-)

          • Joel says:

            Hey Ben is there a way to replay the same level if a certain criteria is not fullfilled. My idea is to have 4 sets of keys, 1 is the correct one and the level progresses but if one of the other 3 is picked up, when you go to the door and press down i want it to restart the same level.

  6. Matthews says:

    Hey Ben, how do I change where the character is loaded? I created a level and the Character seems to spawn way at top then lands on the floor.

    • Ben Reynolds says:

      I think the initial position depends on what you set the scrollX and scrollY variables to when you load a new level. You might need to experiment with their values a bit before you get the player exactly where you want. Let me know how it goes.

  7. BlueLightning says:

    Hi whenever i take all ur code and put it into my game it works but it comes up with this output error

    TypeError: Error #1010: A term is undefined and has no properties.
    at startGame999999_fla::MainTimeline/gotoLevel2()
    at startGame999999_fla::MainTimeline/nextLevel()
    at startGame999999_fla::MainTimeline/keyDownHandler()

    yet when i play yours it works without that error,,, and also my levels keep flashing/switching between eachother while playing….also if anyone could help with making coins that add to a score. Thanks everyone!

    • BlueLightning says:

      Coins that when touched by player add to score and disappear when touched,

    • Jimbob says:

      Hey, I’m getting exactly the same thing (well, the ‘startGame999999′ obviously has my own name), not sure why… I’ll have a play about with the coding and see if I can fix it. Pasting the source code in gave the same result, too.

      With regards to your flashing/switching, are you putting a stop(); function in the actions layer of each container?

      • Jimbob says:

        Ah! Didn’t take long, I’ve fixed it.

        The problem was I hadn’t given my visuals movie clip the instance name ‘visuals’, so I guess it was trying to find something that ‘didn’t exist’. Just go through all your movie clips and make sure they all have the correct instance names.

        If, of course, you’re still having the same issue 3 months on ;)

  8. legice says:

    ok I have done everything (if correct that is the question), but my game keeps spazzing the visual and collision layers and I can not move the character any more, even thou I never touched the character move controlls. this happened even before putting in the code and after makeing the layer changes ( so I put stop() on every layer and nothing improved).
    any ideas anybody?

    ps – can’t you just convert your cs 5.5 file into a later version, as that really helped when checking where I messed up in the code or visuals.
    thanks

    • Jimbob says:

      Not sure if your P.S. would make this an issue (and assuming you used the same instance names), but have you tried downloading the source file and copying all the code inside into your file? Then test if it works, if not then it’s the same as me – some problem with the objects themselves.

  9. Ciara Pereira says:

    Hi, I really hope somebody can help I’ve been building a game for college based on this tutorial and changing a few things as I go and it’s all working fine so far but the handup date is rly soon and I cant figure out how to do a lives or health bar function and an end screen for i my character loses all his lives, I’m super super desperate pls if anybody could help :)

    • Ciara Pereira says:

      Well i got the health bar sorted :) but have spent the whole day trying to write a game over function and go to end screen on main timeline frame3 with a replay btn but am constantly geting this error “Error #1009: Cannot access a property or method of a null object reference.” if anyone can help me pls, thx in advance :)

      • Jimbob says:

        Double-check ALL your instance names and coding which refers to instance names! Or it could be that you’re referring to an instance on a different frame to the one you’re currently on?

        I’ve only ever had that error when I’ve forgotten an instance name…

  10. Frankenstein says:

    Nice but 1 question if i want different backround instead of clouds in level 2 map i just simply delet cluds and put image or something the layer and its working level to or need to create new keyframe and in the layer and new action layer angd right stop(); in the first keyframe on actions layer? so is it possible? i mean if i want new background image in level 2 i can do this?
    sry for my english

  11. AndyC says:

    Hey man thanks for the tutorials. Im trying to do the multiple levels but instead of having to collect a key, the user just has to reach a flag at the end of the level but once ive finished the coding it says access of undefined property for both the keyUpHandler and also loop. Any ideas as to why this could be happening?

  12. mahh360 says:

    Hey Ben, in the first movie of the tutorial, the player does not touch the ground! Instead, he just falls. Can you fix that bug?

  13. Jonathan Grenier says:

    I cannot make the level 2 work it say this :
    TypeError: Error #1010: Un terme n’est pas défini et n’a pas de propriété.
    at Robota1_fla::MainTimeline/keyDownHandler()

  14. Jonathan Grenier says:

    alsom whenever I put those line in comment mode the error don’t happen and nothing happen, here are the lines that cause the error message to appear :

    if(doorOpen && player.hitTestObject(back.other.lockedDoor)){
    //proceed to the next level if the player is touching an open door
    nextLevel();
    }

    everything else work just fine in my program, please help me someone I’m going nuts over here….

  15. Jonathan Grenier says:

    ok forget about me I figured it out now it goes to level 2.
    Unfortunaly, I have the same error 2007 for collecting items in the level 2. I really don’t understand why collecting items works on level 1 but on level 2 it dont work, my objects have the same names on frame 2 of my back object than on the frame 1. Do I need to create new object for every level ? Cus it’s very weird the way to program works, as if changing frame made the program loose all informations on objects on that new frame….it’s a shame to not be able to re use the code

  16. Jonathan Grenier says:

    I fixed everything by myself thank you for you help, now I’ll eat then I’ll do next tuts…

  17. Sophia Haq says:

    Hi, thanks for this tute, it’s brilliant!

    I’m having a tiny issue though, I’m not doing the multi levels, I just want to jump to a scene when the character reaches the door.

    I used gotoAndStop(0, “end”); instead of calling up the nextlevel function, but I keep getting an error which says:

    “Cannot access a property or method of a null object reference”.

    Any help would be much appreciated.

    Thank you!

  18. aweifnkcjcmjdxsad adsd fsegzf says:

    I really hope you see this – I’m having a HUGE problem. Whenever I run the game I get error 1120: access of undefined property keyUpHandler. I’ve even tried copying your code completley – no change in my game. Yet when I play your game, it works perfectly. Pleaaase help, it would be much appreciated.

  19. lucas200206 says:

    Bob, your tutorials are AWESOME, and since i started the “Pong” and this “Platform” tutorial, i discovered much new features that i didn’t even know that flash could do!

    But, here goes the Daily Question Challenge:

    -I’m making a sequel to this game: Two Red Buttons (http://www.newgrounds.com/portal/view/555348) but i don’t know how to animate things without exiting that level-frame. Any solution?

  20. Megan Rhoden says:

    I am making a game for one of my classes right now for college and I am having problems making my character go to level 2. The door disappears when you press down and it my character stays on level one. It says…

    TypeError: Error #1010: A term is undefined and has no properties.
    at REDO_fla::MainTimeline/gotoLevel2()
    at REDO_fla::MainTimeline/nextLevel()
    at REDO_fla::MainTimeline/keyDownHandler()

    Do you have any idea on what it could mean? I just copy and pasted your code into Frame 1 of the actions where all the code goes, so I don’t know what I did wrong?

    Thanks

    • Megan Rhoden says:

      I figured it out. I was reading though the comments and someone said something about forgetting to name their visuals instance name and sure enough that is exactly what it was. GREAT TUTORIALS!

  21. Maedbh says:

    Hiya, just found this tutorial and I’m wondering how to exit the game and go to a new frame after the door is reached and opened?
    Speedy reply much appreciated!

    – M

  22. Rick says:

    Help! I end up getting this.

    TypeError: Error #2007: Parameter hitTestObject must be non-null.
    at flash.display::DisplayObject/_hitTest()
    at flash.display::DisplayObject/hitTestObject()
    at TheHunterWithinv0_Scene1_fla::MainTimeline/loop()

  23. jinse says:

    Very nice tutorial man. I just have one suggestion. If u want to add more then 2 levels u can do this without having to make an entire new function for every level. Here is the code. I hope it helps!

    function nextLevel():void{
    currentLevel++;
    trace(“Next Level: ” + currentLevel);
    gotoNextLevel(currentLevel);
    }

    function gotoNextLevel(e:int):void{
    back.other.gotoAndStop(e);
    back.visuals.gotoAndStop(e);
    back.collisions.gotoAndStop(e);
    scrollX = 0;
    scrollY = 500;

    keyCollected = false;
    back.other.doorKey.visible = true;
    doorOpen = false;
    back.other.lockedDoor.gotoAndStop(1);

  24. Lee Jenkinson says:

    hello can anyone help me with having a different parallax background for level 2?? just can’t figure it out and its important for my final year project, thanks :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s