Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package example.button
- {
- import nape.constraint.LineJoint;
- import nape.phys.Body;
- import nape.phys.Compound;
- /**
- * ...
- * @author liu wong
- *
- */
- public class buttonInfo
- {
- private static const delta:Number = 0.75;
- private static const delta2:Number = 0.25;
- public var compound:Compound;
- public var mainBody:Body;
- public var secondBody:Body;
- public var len1:Number;
- public var len2:Number;
- public var trigger:Boolean = false;
- public var counterOn:int = 0;
- public var counterOff:int = 0;
- public var onTrigger:Function = null;
- public var id:int = 0;
- public function buttonInfo(c:Compound, a:Body, b:Body, l:Number):void
- {
- compound = c;
- mainBody = a;
- secondBody = b;
- len1 = l * delta;
- len2 = l * delta2;
- }
- public function update():void
- {
- var l:Number = mainBody.position.sub(secondBody.position).length;
- if (trigger == false)
- {
- if (l <= len2)
- {
- trigger = true;
- counterOn++;
- if (onTrigger != null)
- onTrigger(this, true);
- }
- }
- else
- {
- if (l >= len1)
- {
- trigger = false;
- counterOff++;
- if (onTrigger != null)
- onTrigger(this, false);
- }
- }
- }
- public function free():void
- {
- compound.space = null;
- mainBody = null;
- secondBody = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement