Go Back   kirupaForum > Flash > Game/AI Programming

Reply
 
Thread Tools Display Modes
Old 02-17-2010, 05:10 PM   #1
ligaa
AS3 Game Designer
 
ligaa's Avatar
Location Phoenix, AZ

Posts 12
[opinion needed] best way to create/render multiple movieclips?

Hey all

I'm starting work on a new game that has a lot of shapes dynamically generated on the stage. They're all the same shape, just different sizes. I figured the best way to do this would be an array of movieclips, but then I remembered hearing that things run much better when you clone things out of Bitmap Data. Finding good examples of either solution has been difficult, so I thought I'd try my own.

Here's what I have so far:
PHP Code:
package {
    
import flash.display.MovieClip;
    
import flash.display.Shape;
    
import flash.display.Bitmap;
    
import flash.display.BitmapData;
    
    public class 
Magnetron extends MovieClip {
        private var 
circleSize:Number;
        private var 
maxSize:Number;
        private var 
numPullers:Number;
        private var 
numPushers:Number;
        
        public function 
Magnetron():void {
            
createPullers();
        }
        
        private function 
createPullers():void {
            
numPullers 10;
            
maxSize 50;
            
            for(var 
i:Number 0numPullersi++){
                
circleSize Math.round(Math.random()*maxSize);
                if(
circleSize 10){
                    
circleSize 10;
                }
                
                var 
circle:MovieClip = new MovieClip();
                
circle.name "circle"+i;
                
circle.graphics.beginFill(0x000000);
                
circle.graphics.drawCircle(circleSize,circleSize,circleSize);
                
circle.graphics.endFill();
    
                var 
pullerBMData:BitmapData = new BitmapData(circleSize*2circleSize*2true0xFFFFFF);
                
pullerBMData.draw(circle);
                var 
puller:Bitmap = new Bitmap(pullerBMData);
                
puller.Math.round(Math.random()*stage.stageWidth);
                
puller.Math.round(Math.random()*stage.stageHeight);
                
stage.addChild(puller);
            }
        }
        
//=====================================================================
    
}

Well, it works. It puts a bunch of black circles on the stage in random spots, and there's transparency around the circles. However, here are my concerns:
  1. Is this the right way to copy things out of BitmapData?
  2. If not, what is the right way? Or, what's a better way?
  3. If so, will this actually save on loading/processing?
  4. How will this method affect hit detection? And what's the best form of hit detection to use here?
  5. Is it still a good idea to load the different shapes into an array to keep track of them? Or is there a better way to keep track?
A hundred questions, and I've just started. I thank anyone who can offer some insight into this!

__________________
trace("Hello world!");
ligaa is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?

Old 02-19-2010, 02:47 PM   #2
rumblesushi
Registered User
 
rumblesushi's Avatar
Location Ingletown innit.

Posts 692
This is 100% not the right way to do it

You shouldn't be using movieclips at all. Replace what you would be using movieclips for with your own custom class, with variables x/y/scale and anything else you need.

You could use BMF to draw these objects to the same graphics object every frame.

Collision detection would work the same way it does for anything else, you just use the coordinates of your object for the collision, then render the object using it's coordinates.

You don't need movieclips, and you don't need draw either.

Look into copyPixels. It's fast, but if your shapes are animated or scale dynamically, you'll of course need a prebuilt sprite sheet, or frame sheet.

__________________
Performance King.
rumblesushi is offline   Reply With Quote
Old 02-23-2010, 06:49 PM   #3
mxrider108
Skawesome!
 
mxrider108's Avatar
This thread may be relevant to you if you decide to use bitmap rendering (very fast!): http://www.kirupa.com/forum/showthread.php?t=343909
mxrider108 is offline   Reply With Quote
Old 03-04-2010, 02:05 PM   #4
ligaa
AS3 Game Designer
 
ligaa's Avatar
Location Phoenix, AZ

Posts 12
Thank you rumblesushi and mxrider108! (And sorry for the late response!)

The information you both provided is very helpful. But I'm not sure it even needs to get as complicated as blitting and all. I'm essentially going to have three objects: a ship, a black sphere, and a red sphere. The spheres are rendered in different sizes but are all essentially the same thing.

So I'll go with BitmapData/Bitmap and copyPixels and see how that works.

__________________
trace("Hello world!");
ligaa is offline   Reply With Quote
Reply

Tags
array, bitmap, bitmapdata, dynamic, movieclip


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:27 PM.

SHARE:

SUPPORTERS:

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com