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.
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;
}
}
}
{
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;
}
}
}