[casual_games] Game Development in AS3

Jónas Björgvin Antonsson jonas at gogogic.is
Wed Nov 28 03:26:01 EST 2007


This is from one of the guys at my office:

One of my preferred solutions is to have a static variable in the player's class that references the player's movieclip (or the class itself in some cases, if you only store the player's graphics in the class' display list or have the class linkaged to the movieclip).



So for example, I have a class called Player that extends MovieClip so I can add it to a DisplayObjectContainer's display list. In your case this class would be the gun the human player controls. This class has a static class variable, let's just call it private static var _self:Player .

In the Player constructor, it puts a reference to itself into the static variable; Player._self = this . Then we add a getter function for other classes to reference the class;

public static function get self():Player {

return Player._self;

}

Now, any other class can reference the player just by typing Player.self .



By using similar method you could store all of the player's shots in a static array in the Player class, and when the airplanes want to hitTest every shot, it just loops through this array and hitTests every shot. The shots would then have to add themselves and more importantly (to prevent memory leak and slow performance) remove themselves from that array.


________________________________

From: casual_games-bounces at igda.org on behalf of dayvid jones
Sent: þri. 27.11.2007 05:01
To: casual_games at igda.org
Subject: [casual_games] Game Development in AS3



In AS3 how does a movie clip reference or find another movieclip?
Example, let's say I have a game that has enemy airplanes and the
play uses a gun to shoot them down, the airplanes are randomly
selected and addchild is used to place them in the DisplayObject on
the stage by the document class. Now lets say that the airplanes drop
bombs, so the airplanes have their own class linked to the airplane
movie clips in the library, this class uses a timer to drop bombs by
using addchild and moves the plane. The bombs have their own class
that move them down the screen and do a hittest looking for the
players gun. How do you do this in AS3? In AS2 I would use a _root to
allow the Bomb class to find the Gun MC. So in AS3 how do classes
find MCs on the stage?

Is my approach totally off for AS3? I'm trying to migrate from AS2
game development to AS3, and my biggest problems is the DiplayObject ; (

Does anyone know of a book or website that gives instruction or
examples for a game with enemies that shoot back? Or can anyone
answer my question?

___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___

D A Y V I D J O N E S

"Spock has a beard!?
Dude, we are totally in the wrong universe..."

Free Games, Free Music, Cool Photos and Documentaries!
http://www.dayvid.com <http://www.dayvid.com/>

...shouldn't you be listening to Calico Radio?
http://www.CalicoRadio.com <http://www.calicoradio.com/>

music for the mAdNeSs!
http://www.DJGecko.com <http://www.djgecko.com/>












_______________________________________________
Casual_Games mailing list
Casual_Games at igda.org
http://www.igda.org/casual-subscribe
Archive: http://www.igda.org/casual-subscribe
Archive Search: http://www.google.com/coop/cse?cx=010373383720242846960%3Az3tdwggxil8
List FAQ: http://www.igda.org/wiki/index.php/Casual_Games_SIG/Casual_Games_List_FAQ


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 6863 bytes
Desc: not available
Url : <http://seven.pairlist.net/pipermail/casual_games/attachments/20071128/9d0f8200/attachment.bin>


More information about the Casual_Games mailing list