quick2b skinning

I made this class, after seeing what was used in the Actor demo.

Just seems like an awful lot of code to use objects from the flash library dynamic. Is there a better way or a built in quickb2 class that handles this better?

It would be awesome if we could... circle = qb2Stock.newCircleShape(new amPoint2d(100,stage.stageHeight / 2),30,1, movieClipName); NOTICE movieClipName which would be how we pass the actual movieclip that has the visual design.

Its a class to skin objects. The way you use the class.
Code:
var Skin1:Skin = new Skin(sWidth,sHeight,world,circle_mc);

Code:
package
{
   import As3Math.geo2d.*;
   import QuickB2.objects.tangibles.*;
   import QuickB2.stock.*;
   import surrender.srVectorGraphics2d;
   import QuickB2.loaders.qb2FlashLoader;

   //actors
   import QuickB2.internals.qb2InternalPropertyAndFlagCollection;
   import QuickB2.misc.acting.qb2FlashSpriteActor;

   import flash.display.MovieClip;
   import flash.utils.getDefinitionByName;
   import flash.display.Stage;


   public class Skin
   {
      private var img:MovieClip;
      private var _rootStageWidth:Number;
      private var _rootStageHeight:Number;
      private var _rootWorld:qb2World;
      private var _skinMC:MovieClip;
      private var body2:qb2Body;

      public function Skin(rootStageWidth, rootStageHeight, rootWorld, skinMC:MovieClip)
      {
         _rootStageWidth = rootStageWidth;
         _rootStageHeight = rootStageHeight;
         _rootWorld = rootWorld;
         _skinMC = skinMC;
         // constructor code
         addObject();
      }
      public function addObject():void
      {
         var pic:qb2Body = makePic(0, _skinMC);
         addPic(pic);
         //add to world
         _rootWorld.addObject(pic);
      }
      private function makePic(sType:uint, mc:MovieClip):qb2Body
      {
         var shapeType:uint = sType;
         img = mc;

         var wrapper:qb2FlashSpriteActor = new qb2FlashSpriteActor();
         wrapper.addChild(img);

         body2 = new qb2Body();
         body2.actor = wrapper;

         if (shapeType == 1)
         {
            body2.addObject(qb2Stock.newRectShape(new amPoint2d(img.width / 2, img.height / 2), img.width, img.height));
         }
         else
         {
            body2.addObject(qb2Stock.newCircleShape(new amPoint2d(img.width / 2,img.height / 2),img.width/2,1));
         }
         body2.mass = 1;
         body2.isBullet = true;
         body2.hasFixedRotation = true;
         return body2;

      }
      //--- Move pic to center.  Note that it's top-left oriented, so has to be adjusted a bit.
      private function addPic(picBody:qb2Body):void
      {
         var center:amPoint2d = new amPoint2d(_rootStageWidth / 2, _rootStageHeight / 2);

         picBody.position.copy(center);
         picBody.position.x -=  picBody.getBoundBox().width / 2;
         picBody.position.y -=  picBody.getBoundBox().height / 2;

      }


   }

}
To add to the topic. I really dig this...

Code:
var loader2:qb2FlashLoader = new qb2FlashLoader();
         var smiles:qb2Body = loader2.loadObject(Smiley_mc) as qb2Body;
         world.addObject(smiles);


But dislike the fact that I have to actually have the movieclip on the stage of the fla , name it something in the property file inspector, and also choose the correct class in the actual library when creating the movie clip.
It doesn't have to be on stage. In the library, just right click on an asset, then do (I think it's called) Export for Actionscript.
dougk16 wrote:
It doesn't have to be on stage. In the library, just right click on an asset, then do (I think it's called) Export for Actionscript.



1. See the screen shot attached so you can see how I already exported for AS.

2.
Code:
public var circle_mc:Circle_mc = new Circle_mc();


3.
Code:
var loader2:qb2FlashLoader = new qb2FlashLoader();
         var smiles:qb2Body = loader2.loadObject(circle_mc) as qb2Body;
         world.addObject(smiles);


4. I get this error.
Code:
Error: Invalid source provided.
   at QuickB2.loaders::qb2FlashLoader/loadObject()[/Users/robert.olide/Sites/qb2/src/QuickB2/loaders/qb2FlashLoader.as:80]
   at Main()[/Users/Sites/qb2/examples/HelloWorld/src/Main.as:90]


Its odd because before the last update from the svn head, this would work. However I would do it a bit different were I used a shaped that extended this as the base class in the property settings when exporting for AS
Code:
QuickB2.loaders.proxies.qb2ProxyBody
But now that doesn't work either.

Does that error tel you anything?
This one worked.


Code:
public var smiley:Smiley = new Smiley();

Code:
var loader2:qb2FlashLoader = new qb2FlashLoader();
         var smiles:qb2Body = loader2.loadObject(smiley) as qb2Body;
         world.addObject(smiles);




Which as you can see , takes the cost of having to set up a movieclip and extend the
Code:
QuickB2.loaders.proxies.qb2ProxyBody
and also add a Proxy circle shape.

Just wondering which other ways or if there is a way to simply set up a movieclip and use that movieclip as the skin. Long story shoirt I am trying to skin my shaoes and bodys with out having to use components and just use movieclips or sprites programmaticly with the least code possible.
Hi,

I reread this post, and I really like your suggestion to add actor as a parameter to some of the qb2Stock functions. I think I will do that.

For now, I suggest using the actor property of qb2Tangible (or qb2Object, depending on which SVN version you have, because I changed this recently), instead of qb2FlashLoader.

qb2FlashLoader is something that I think is a really cool idea, but unfortunately FlashCS5 makes things very difficult. The program simply wasn't designed for what QuickB2 needs, and it's very hard to support it.

The best solution would be to create a custom editor, but obviously this is a huge project by itself.

Thanks,

Doug
dougk16 wrote:
Hi,

I reread this post, and I really like your suggestion to add actor as a parameter to some of the qb2Stock functions. I think I will do that.

For now, I suggest using the actor property of qb2Tangible (or qb2Object, depending on which SVN version you have, because I changed this recently), instead of qb2FlashLoader.

qb2FlashLoader is something that I think is a really cool idea, but unfortunately FlashCS5 makes things very difficult. The program simply wasn't designed for what QuickB2 needs, and it's very hard to support it.

The best solution would be to create a custom editor, but obviously this is a huge project by itself.

Thanks,

Doug


That would be an awesome addition!

As far as qb2Tangible

is it as simple as
Code:
var t:qb2Tangible = new qb2Tangible();
      t.actor(circle_mc);
      


Any chance you can point me to were you used this in the demo or post a snippet of code for better direction?

Original thread: https://box2d.org/forum/viewtopic.php?t=6831