Reset enemies and props in As3
- moynzy
-
moynzy
- Member since: Jan. 14, 2008
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
Hey guys, and girls. I have a question.
In games, when you collect something that object dissapears.
if(hero.hitTest.enemy)
{ enemy dissapear. parent.remove(enemy), or in as2 _root.enemy.removeMovieclip();}
Question is, when you reset the game, for example, go back to the menu and then press play again,
you will see that enemy is not there, because it's been removed.
How can I resolve this other than refresh the swf file?
- Sam
-
Sam
- Member since: Oct. 1, 2005
- Offline.
-
- Forum Stats
- Moderator
- Level 19
- Programmer
Simply add them again. If you're using a mixture of the Flash IDE (i.e. frames, placed movieclips etc) and code to build your games, I'd highly suggest moving over to something like FlashDevelop and only use code to build your games.
- moynzy
-
moynzy
- Member since: Jan. 14, 2008
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
At 4/10/14 10:03 AM, Sam wrote: Simply add them again. If you're using a mixture of the Flash IDE (i.e. frames, placed movieclips etc) and code to build your games, I'd highly suggest moving over to something like FlashDevelop and only use code to build your games.
Hey Sam, I'm using a mixture of flash Develop and Flash.
You're telling me to add the objects in dynamically?
You see I'm using frames.
So frame 1 contains start menu, frame 2 contains game, frame 3 contains end/win screen.
You suggest.
if(current frame is 2)
{ add everything that you will remove, if you don't remove them, then don't add them dynamically)
you mean something like this?
- GeoKureli
-
GeoKureli
- Member since: Apr. 1, 2003
- Offline.
-
- Forum Stats
- Supporter
- Level 19
- Game Developer
just don't use frames. Make a class that extends MovieClip, store it's initial position on creation, and add a reset function that sends it back to it's original state.
public class Asset extends MovieClip{
private var resetPos:Point;
public function Asset(){
super();
resetPos = new Point(x, y);
}
public function reset():void{
x = resetPos.x;
y = resetPos.y;
}
}
have your library assets use that class via AS Linkage
then whenever you want it to reset just say myPickupItem.reset();
This blog I made | This game sucks | FlxGreed | Home Run Swingers: Rhythm Baseball
many typos

