Hi guys,
Sorry about the vague topic title but I'm not quite sure what the problem here is. Here is my main class titled "ThumbnailsHolder.as"...
This is "PortfolioThumbActor.as"...
And "PortfolioThumb.as", which extends a library item with the visual structure goes like this...
Sorry about the long post but basically, I see my three thumbnails on the stage no problem but there's no movement.
Thanks so much for taking the time to read my post. If anybody has any ideas, I'd be really appreciative!
Sorry about the vague topic title but I'm not quite sure what the problem here is. Here is my main class titled "ThumbnailsHolder.as"...
Code:
package com.view.portfolio
{
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import com.model.CreativeVO;
import com.model.SiteData;
import Box2D.Collision.Shapes.b2PolygonDef;
import Box2D.Collision.b2AABB;
import Box2D.Common.Math.b2Vec2;
import Box2D.Dynamics.b2Body;
import Box2D.Dynamics.b2BodyDef;
import Box2D.Dynamics.b2World;
public class ThumbnailsHolder extends Sprite
{
private var m_world : b2World;
public var m_physScale : Number = 30;
public var m_iterations : Number = 10;
public var m_timeStep : Number = 1.0/30.0;
public var actors : Array;
public function ThumbnailsHolder()
{
actors = new Array();
var worldAABB:b2AABB = new b2AABB();
worldAABB.lowerBound.Set(-1000.0, -1000.0);
worldAABB.upperBound.Set(1000.0, 1000.0);
// Define the gravity vector
var gravity:b2Vec2 = new b2Vec2(0.0, -10.0);
// Allow bodies to sleep
var doSleep:Boolean = true;
// Construct a world object
m_world = new b2World(worldAABB, gravity, doSleep);
addEventListener(Event.ENTER_FRAME, update);
//////////////////////////////
for (var i : int = 0; i < 3; i++) {
addThumbnail(new Point((i+1) * 150, 150), 80, 80, SiteData.getInstance().creatives[i]);
}
}
private function addThumbnail(position : Point, width : Number, height : Number, creativeVO : CreativeVO) : void
{
// Define the body
var bodyDef:b2BodyDef = new b2BodyDef();
bodyDef.position.Set(position.x * m_physScale, position.y * m_physScale);
// Define the shape
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.SetAsBox(width / (m_physScale*2), height / (m_physScale*2));
boxDef.density = 1.0;
boxDef.friction = 0.3;
boxDef.restitution = 0.2;
// Add the body to the world
var myBody:b2Body = m_world.CreateBody(bodyDef);
myBody.CreateShape(boxDef);
myBody.SetMassFromShapes();
// Create actor and the visual representation
var thisThumb : PortfolioThumb = new PortfolioThumb(creativeVO);
var thisActor : PortfolioThumbActor = new PortfolioThumbActor(myBody, thisThumb);
actors.push(thisActor);
addChild(thisThumb);
}
private function update(e : Event) : void
{
m_world.Step(m_timeStep, m_iterations);
for each (var a:PortfolioThumbActor in actors)
{
var bodyPosition:b2Vec2 = a.body.GetPosition();
var bodyRotation:Number = a.body.GetAngle();
a.graphic.x = bodyPosition.x / m_physScale;
a.graphic.y = bodyPosition.y / m_physScale;
a.graphic.rotation = bodyRotation * (180/Math.PI) % 360;
}
}
}
}
{
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import com.model.CreativeVO;
import com.model.SiteData;
import Box2D.Collision.Shapes.b2PolygonDef;
import Box2D.Collision.b2AABB;
import Box2D.Common.Math.b2Vec2;
import Box2D.Dynamics.b2Body;
import Box2D.Dynamics.b2BodyDef;
import Box2D.Dynamics.b2World;
public class ThumbnailsHolder extends Sprite
{
private var m_world : b2World;
public var m_physScale : Number = 30;
public var m_iterations : Number = 10;
public var m_timeStep : Number = 1.0/30.0;
public var actors : Array;
public function ThumbnailsHolder()
{
actors = new Array();
var worldAABB:b2AABB = new b2AABB();
worldAABB.lowerBound.Set(-1000.0, -1000.0);
worldAABB.upperBound.Set(1000.0, 1000.0);
// Define the gravity vector
var gravity:b2Vec2 = new b2Vec2(0.0, -10.0);
// Allow bodies to sleep
var doSleep:Boolean = true;
// Construct a world object
m_world = new b2World(worldAABB, gravity, doSleep);
addEventListener(Event.ENTER_FRAME, update);
//////////////////////////////
for (var i : int = 0; i < 3; i++) {
addThumbnail(new Point((i+1) * 150, 150), 80, 80, SiteData.getInstance().creatives[i]);
}
}
private function addThumbnail(position : Point, width : Number, height : Number, creativeVO : CreativeVO) : void
{
// Define the body
var bodyDef:b2BodyDef = new b2BodyDef();
bodyDef.position.Set(position.x * m_physScale, position.y * m_physScale);
// Define the shape
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.SetAsBox(width / (m_physScale*2), height / (m_physScale*2));
boxDef.density = 1.0;
boxDef.friction = 0.3;
boxDef.restitution = 0.2;
// Add the body to the world
var myBody:b2Body = m_world.CreateBody(bodyDef);
myBody.CreateShape(boxDef);
myBody.SetMassFromShapes();
// Create actor and the visual representation
var thisThumb : PortfolioThumb = new PortfolioThumb(creativeVO);
var thisActor : PortfolioThumbActor = new PortfolioThumbActor(myBody, thisThumb);
actors.push(thisActor);
addChild(thisThumb);
}
private function update(e : Event) : void
{
m_world.Step(m_timeStep, m_iterations);
for each (var a:PortfolioThumbActor in actors)
{
var bodyPosition:b2Vec2 = a.body.GetPosition();
var bodyRotation:Number = a.body.GetAngle();
a.graphic.x = bodyPosition.x / m_physScale;
a.graphic.y = bodyPosition.y / m_physScale;
a.graphic.rotation = bodyRotation * (180/Math.PI) % 360;
}
}
}
}
This is "PortfolioThumbActor.as"...
Code:
package com.view.portfolio
{
import flash.display.DisplayObject;
import Box2D.Dynamics.b2Body;
public class PortfolioThumbActor
{
private var _body : b2Body;
private var _graphic : DisplayObject;
public function PortfolioThumbActor(b:b2Body, g:DisplayObject){
_body = b;
_graphic = g;
}
public function get body() : b2Body
{
return _body;
}
public function get graphic() : DisplayObject
{
return _graphic;
}
}
}
{
import flash.display.DisplayObject;
import Box2D.Dynamics.b2Body;
public class PortfolioThumbActor
{
private var _body : b2Body;
private var _graphic : DisplayObject;
public function PortfolioThumbActor(b:b2Body, g:DisplayObject){
_body = b;
_graphic = g;
}
public function get body() : b2Body
{
return _body;
}
public function get graphic() : DisplayObject
{
return _graphic;
}
}
}
And "PortfolioThumb.as", which extends a library item with the visual structure goes like this...
Code:
package com.view.portfolio
{
import flash.display.Sprite;
import com.model.CreativeVO;
import com.utils.DisplayItems;
public class PortfolioThumb extends PortfolioThumb_GUI
{
private var _image : Sprite;
private var _maskClip : Sprite;
public function PortfolioThumb(creativeVO : CreativeVO)
{
_maskClip = DisplayItems.drawRectangle(67, 67, 0xff0000, true);
_maskClip.x = _maskClip.y = -33.5;
_image = new Sprite();
_image.addChild(creativeVO.thumbnail);
_image.x = _image.y = -40;
_image.mask = _maskClip;
addChild(_image);
addChild(_maskClip);
}
}
}
{
import flash.display.Sprite;
import com.model.CreativeVO;
import com.utils.DisplayItems;
public class PortfolioThumb extends PortfolioThumb_GUI
{
private var _image : Sprite;
private var _maskClip : Sprite;
public function PortfolioThumb(creativeVO : CreativeVO)
{
_maskClip = DisplayItems.drawRectangle(67, 67, 0xff0000, true);
_maskClip.x = _maskClip.y = -33.5;
_image = new Sprite();
_image.addChild(creativeVO.thumbnail);
_image.x = _image.y = -40;
_image.mask = _maskClip;
addChild(_image);
addChild(_maskClip);
}
}
}
Sorry about the long post but basically, I see my three thumbnails on the stage no problem but there's no movement.
Thanks so much for taking the time to read my post. If anybody has any ideas, I'd be really appreciative!