Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 9 of 9

Thread: how to put movie clips on stage and remove them

  1. #1

    how to put movie clips on stage and remove them

    Hey guys,

    I am making a platform game and I decided to use a scrolling background by cacheing it so I could repeat the background and it would make the game faster. But the actual platforms, I will put in another mc, which I will put the same code as the moving background so it moves but I'm not going to have it repeat so I need to make a lot of these. I wanted to just store these off stage but I know this will slow it down significantly so any ideas on how to store these movie clips somewhere like the library and call them up when the character is approaching it and removing the other mc of platform so it makes the game run faster?

    Please help!!

    Abs

  2. Quote Originally Posted by abs55 View Post
    Hey guys,

    I am making a platform game and I decided to use a scrolling background by cacheing it so I could repeat the background and it would make the game faster. But the actual platforms, I will put in another mc, which I will put the same code as the moving background so it moves but I'm not going to have it repeat so I need to make a lot of these. I wanted to just store these off stage but I know this will slow it down significantly so any ideas on how to store these movie clips somewhere like the library and call them up when the character is approaching it and removing the other mc of platform so it makes the game run faster?

    Please help!!

    Abs
    Are you familiar with attachMovieClip ()?

  3. #3
    Yeah, I know attachMovieClip and removeMovieClip but I'm not sure how to implement them into the game because I don't know how to put them in a specific place and I'm not sure if it puts too much on the processor so it'll slow the game. Also, there is an enemy that the player has to follow but if the player is left behind and the enemy goes past the first movie clip and the player doesn't, then the next movie clip isn't attached so the enemy will be taken off the game, I think. Thanks for the help anyway.

  4. #4
    abs55, you really do not have any clear concept about movieclips or library yet! What you are thinking went in the right direction, but is a bit offtrack. First of all, just the number of instances of a mc wont put much pressure on the processor unless you have some code the computes on all of them! Calculating code is the actual processor intensive part.

    For example, you can create many bullets and have them be destroyed after sometime, without lag, but try creating a single bullet and let it go off to infinity with some distance checking code in it...and it will soon start to lag.

    I dont know your entire gameplan so i cant say anything specific but you should design the level with a tile based approach, such that, you can generate the level as you go on. Also, you can layout the ground mc or such which have no codes in them before hand, and you can also attach the enemies, just dont execute all their codes if they are outside view.

    Code:
    var my_distance=Math.sqrt(((player._x-this._x)*(player._x-this._x))+((player._y-this._y)*(player._y-this._y)))
    if(my_distance<(Stage.width/2)+30)
    {
     //execute the enemy code
    } 
    else dont
    this type of checking will lessen the burden on processor, but still it will be processor intensive if there are too many instances to check through. Thus you should not perform this check every step!

    And lastly read tonypa's tutorials on tilebased level creation to build larger yet lag free levels.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  5. #5
    Quote Originally Posted by bluemagica View Post
    abs55, you really do not have any clear concept about movieclips or library yet! What you are thinking went in the right direction, but is a bit offtrack. First of all, just the number of instances of a mc wont put much pressure on the processor unless you have some code the computes on all of them! Calculating code is the actual processor intensive part.

    For example, you can create many bullets and have them be destroyed after sometime, without lag, but try creating a single bullet and let it go off to infinity with some distance checking code in it...and it will soon start to lag.

    I dont know your entire gameplan so i cant say anything specific but you should design the level with a tile based approach, such that, you can generate the level as you go on. Also, you can layout the ground mc or such which have no codes in them before hand, and you can also attach the enemies, just dont execute all their codes if they are outside view.

    Code:
    var my_distance=Math.sqrt(((player._x-this._x)*(player._x-this._x))+((player._y-this._y)*(player._y-this._y)))
    if(my_distance<(Stage.width/2)+30)
    {
     //execute the enemy code
    } 
    else dont
    this type of checking will lessen the burden on processor, but still it will be processor intensive if there are too many instances to check through. Thus you should not perform this check every step!

    And lastly read tonypa's tutorials on tilebased level creation to build larger yet lag free levels.
    Oh ok, so the code is the main fault for the lag. Before, I thought it was the actual graphics but now I realize it's the code! All the different sections of the level have code in them, which is why it probably goes slow. The thing with the tile based levels is that the enemy need to travel regardless of player so if the next sections of the level is created when the player passes, and the enemy is far ahead, he will be lost somewhere. And I don't want the enemy to stop at a stage to wait for the player to catch up.

    Btw, I realized that when I put in more code for the main character to make new sections to appear when he nears the end of one, the game lagged a lot. I put this code in his mc on right key press. So when I pressed left, he didn't go slow at all. So I also want to know if there is a way I can put all his code somewhere else so it might not make the game lag. I don't know about oop but if it is needed and if you could explain, I would really be grateful.

    Thanks for clearing up my issue with why the game goes slow!

  6. #6
    Umm, I do not really understand what you are saying about this enemy moving ahead of player....if the enemy cannot be seen, then what is the use of having him? You can just calculate his position and put him there when needed!

    I mean think of a bike race game, your competitor gets a few laps ahead of you, so he is invisible to you...and thus you dont need loads of his actions, like say you dont need collision checks with him, you dont need his fuel usage and such, the only thing you need is his speed and direction, to calculate when and where you will meet him next...similarly, in your game, think how you can lessen the objects and their code, and only execute them when needed!
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  7. #7
    Quote Originally Posted by bluemagica View Post
    Umm, I do not really understand what you are saying about this enemy moving ahead of player....if the enemy cannot be seen, then what is the use of having him? You can just calculate his position and put him there when needed!

    I mean think of a bike race game, your competitor gets a few laps ahead of you, so he is invisible to you...and thus you dont need loads of his actions, like say you dont need collision checks with him, you dont need his fuel usage and such, the only thing you need is his speed and direction, to calculate when and where you will meet him next...similarly, in your game, think how you can lessen the objects and their code, and only execute them when needed!
    Well I'm not sure entirely how to do that, I was thinking of doing that but I didn't know how to go about it. Mainly, because some player action might slow him down or stop him completely for a while or the player gets faster so I didn't know how to implement all this into him. I am attaching a basic file that basically lets you move left and right and the enemy is traveling in one direction. This just shows my basic idea, I haven't added in any code for the ground yet.
    Attached Files Attached Files

  8. #8
    well yeah, i see that, but in this simple...umm...demo, i still dont see why you need to actually have the enemy after he has gone offscreen....just calculate his probable position using his speed and place him in the particular position when the time comes....
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  9. #9
    I'm not sure how to do that, if you could help me with it or give me any ideas on how to do it, I would appreciate it. Also, would this method work if after he appears on screen, would he carry on going. In my way, the enemy always keeps moving so it gives a realistic type of movement but I don't know how to do it your way, please could you help me?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012