Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ulfben.slingshot.entities
- {
- import nape.geom.Vec2;
- import nape.phys.Body;
- import nape.space.Space;
- import starling.display.DisplayObject;
- import starling.display.Sprite;
- public class Entity extends Sprite
- {
- public var _isDead:Boolean = false;
- protected var _body:Body = null;
- protected var _space:Space = null;
- protected var _visual:DisplayObject; //MovieClip, Sprite or what have you
- protected var _graphicOffset:Vec2 = new Vec2(0,0); //from PhysicEditor
- public function set body(b:Body):void {_body = b;}
- public function get body():Body {return _body;}
- public function set space(s:Space):void { _space = s; if(_body){_body.space = _space;}}
- public function set allowMovement(b:Boolean):void {_body.allowMovement = b;}
- public function get allowMovement():Boolean {return _body.allowMovement;}
- public function get velocity():Vec2 {return _body.velocity;}
- public function set velocity(v:Vec2):void {_body.velocity = v;}
- public function get angularVel():Number {return _body.angularVel;}
- public function set angularVel(n:Number):void {_body.angularVel = n;}
- public function get position():Vec2 {return _body.position;}
- public function set position(v:Vec2):void {_body.position = v; x = _body.position.x; y = _body.position.y; }
- public function Entity(space:Space)
- {
- super();
- _space = space;
- touchable = false;
- }
- public function setxy(x:Number, y:Number):void
- {
- _body.position.x = x;
- _body.position.y = y;
- }
- private var pos:Vec2; //temp, for re-use.
- public function tick(dt:Number):void
- {
- pos = _body.localPointToWorld(_graphicOffset);
- x = pos.x;
- y = pos.y;
- rotation = _body.rotation;
- }
- override public function dispose():void
- {
- if(_body){
- _space.bodies.remove(_body);
- _body.shapes.clear();
- _body.userData.entity = null;
- _body.userData.graphicOffset = null;
- _body = null;
- }
- if(_visual){
- _visual.removeFromParent(true);
- _visual = null;
- }
- _space = null;
- super.dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement