|
-
[Help] Flash TCG: Waiting for User Input
I'm leaving the old problems up for reference, in case anyone else could use the solutions.
(Resolved)I'm trying to make a trading card game in Flash, and I'm struggling with one major problem; how to get the 100+ cards into Flash, and have Actionscript be able to access them.
My current plan is to make the Card class have a field for a MovieClip, so each card can store it's own image. Then I would have an array with one of each type of card for reference. That way, decks could be represented with a simple array of Numbers.
The problem I'm having is getting a MovieClip from the Library into Actionscript without importing it as a class, or using instance names. Is this even possible? If not, does anybody have any other recommendations for how to do this?
(Resolved) I have each player's turn broken up into two phases. I'm trying to figure out how to best implement the phase transitions while the player is selecting cards.
This is what I have so far. I'm going to add a button to turn playphase to false.
Code:
playphase = true;
stage.addEventListener(MouseEvent.CLICK,pickFromHand);
while(playphase){
}
stage.removeEventListener(MouseEvent.CLICK,pickFromHand);
I handle all the actions of the phase inside of pickFromHand.
I needed a way to suspend the main game method until the player is done with their phase. I came up with this, but I'm hesitant to use what is essentially a while(true) loop. Is there a better way to wait for user input?
(For clarity, the main method of the game is NOT called on every frame)
Last edited by TheAmishPirate; 02-13-2010 at 09:32 PM.
Reason: Problem solved, new one found
-
Pumpkin Carving 2008
So, you want to load a clip from the library that you imported, or do you want to load an external clip?
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
I'd planned on loading them from the library.
-
Pumpkin Carving 2008
Then I guess I'm confused. You want a class to have a movieclip member that references the object in the library? Simply don't give the library object a class reference, and just call it in your class as something like:
Code:
var mc:MovieClip = new Card();
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Lurker at Heart
For something like this I think it would make it most flexible if you represented each card with an XML file (or database entry) that outlined its abilities as well as having a reference to its card type and image. It depends on whether you plan on including booster packs and such.
So first you would load a list of the card IDs for each player, then only load the individual card graphics you need. This would be pretty straightforward using a card class in AS3.
-
 Originally Posted by EgoAnt
For something like this I think it would make it most flexible if you represented each card with an XML file (or database entry) that outlined its abilities as well as having a reference to its card type and image. It depends on whether you plan on including booster packs and such.
So first you would load a list of the card IDs for each player, then only load the individual card graphics you need. This would be pretty straightforward using a card class in AS3.
I should have added that I currently only have about half a year's experience with Flash, though I've been programming for a long time.
I do have a structure like that. There's an overall class Card that has the card data in it. That being said, how exactly would I "load" the card graphics? That's the part that I can't figure out.
-
Pumpkin Carving 2008
That varies from version to version. Are you using AS2 or AS3? AS3 has a nifty Loader class that will let you load the image you should look in to.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Lurker at Heart
I usually add this to projects:
RemoteImage.as
Actionscript Code:
package com.egoant { import flash.display.DisplayObject; import flash.display.Loader; import flash.display.LoaderInfo; import flash.display.Sprite; import flash.events.Event; import flash.net.URLRequest; public class RemoteImage extends Sprite { private var triggerFunction:Function; public function RemoteImage(imageURL:String, triggerFunction:Function = null):void { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.INIT, InitializeImage); loader.load(new URLRequest(imageURL)); this.triggerFunction = triggerFunction; } private function InitializeImage(e:Event):void { var loaderInfo:LoaderInfo = e.target as LoaderInfo; var displayObj:DisplayObject = loaderInfo.loader; displayObj.x = 0 - displayObj.width / 2; displayObj.y = 0 - displayObj.height / 2; addChild(loaderInfo.loader); if (triggerFunction != null) { triggerFunction.call(null, this); } var midSprite:Sprite = new Sprite(); midSprite.x = 0; midSprite.y = 0; midSprite.graphics.lineStyle(1); midSprite.graphics.drawCircle(0, 0, 4); addChild(midSprite); } } }
(I call this one RemoteImage because it will load from a remote server as well)
Then if I have a class that needs an image I do something like this:
Actionscript Code:
var cardImage:RemoteImage = new RemoteImage("myImageURL.png", null); cardImage.x = 10; cardImage.y = 10; addChild(cardImage);
Then all you have to do is pass the URL of the card image to this when you initialize it. I can keep the image names associated with a card in a database or XML file that way, and load them from the server as needed.
One drawback to this method is that in some cases the same image might load multiple times, which you can work around if you are careful.
-
@Imprisoned Pride: AS3
Ooh. That looks good. I'll try this out tomorrow, and let you know if this will work. Thanks for the help!
-
Pumpkin Carving 2008
Note that EgoAnt's example is AS3, and that it does use the Loader class I previously mentioned. Good luck.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Lurker at Heart
Sorry, I just noticed that I had a bunch of extra junk in there that you won't really need, here is the same code with all the extra fluff that relates to that project cut out:
Actionscript Code:
package { import flash.display.DisplayObject; import flash.display.Loader; import flash.display.LoaderInfo; import flash.display.Sprite; import flash.events.Event; import flash.net.URLRequest; public class RemoteImage extends Sprite { public function RemoteImage(imageURL:String):void { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.INIT, InitializeImage); loader.load(new URLRequest(imageURL)); } private function InitializeImage(e:Event):void { var loaderInfo:LoaderInfo = e.target as LoaderInfo; var displayObj:DisplayObject = loaderInfo.loader; addChild(loaderInfo.loader); } } }
And that makes the code to call it a bit simpler, too:
Actionscript Code:
var cardImage:RemoteImage = new RemoteImage("myImageURL.png"); cardImage.x = 10; cardImage.y = 10; addChild(cardImage);
-
It works! Thanks a lot everyone!
If I have any more problems, I'll post them here.
Update: New problem/advice needed. I have each player's turn broken up into two phases. I'm trying to figure out how to best implement the phase transitions while the player is selecting cards.
This is what I have so far. I'm going to add a button to turn playphase to false.
Code:
playphase = true;
stage.addEventListener(MouseEvent.CLICK,pickFromHand);
while(playphase){
}
stage.removeEventListener(MouseEvent.CLICK,pickFromHand);
I handle all the actions of the phase inside of pickFromHand.
I needed a way to suspend the main game method until the player is done with their phase. I came up with this, but I'm hesitant to use what is essentially a while(true) loop. Is there a better way to wait for user input?
(For clarity, the main method of the game is NOT called on every frame)
-
Senior Member
um, you have a loop that cant possibly finish there. It will normally break the Flash Player and stop all code. Why dont you simply put removeListener call into pickFromHand function itself?
-
I think I've figured out how to make this work. I need to break this up into more methods, instead of having one big one.
Thanks tonypa for indirectly helping/inspiring me!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|