Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package example
- {
- import example.button.buttonInfo;
- import example.button.buttonUtils;
- import flash.display.DisplayObjectContainer;
- import nape.geom.Vec2;
- import nape.phys.Body;
- /**
- * ...
- * @author liu wong
- *
- */
- public class buttonExample extends baseExample
- {
- private const spawnPos:Vec2 = new Vec2(50, 50);
- private var buttons:Array/*buttonInfo*/;
- private var circle:Body;
- public function buttonExample(prnt:DisplayObjectContainer):void
- {
- super(prnt);
- }
- override protected function init():void
- {
- super.init();
- space.gravity.setxy(0, 980);
- addHand();
- addWalls();
- var k:int = 12;
- var i:int;
- addRectangle(320, 300, 580, 10, (Math.PI / 180) * 10);
- buttons = new Array();
- for (i = 0; i < k; i++)
- {
- var button:buttonInfo = buttonUtils.createButton(space, new Vec2((640 / (k + 1)) * (i + 1), 200+(100 / (k + 1)) * (i + 1)), 45, 20, 35, (Math.PI / 180) * 10);
- button.id = i;
- button.onTrigger = onButton;
- buttons.push(button);
- }
- circle = addCircle(spawnPos.x, spawnPos.y, 25, 0, false);
- var b:Body = addRectangle(320, 460, 640, 10);
- b.surfaceVel.setxy( -100, 0);
- }
- private function onButton(src:buttonInfo, value:Boolean):void
- {
- if (value == true)
- {
- if (src.id == 11)
- {
- circle.position.set(spawnPos);
- return;
- }
- if (src.id == 7)
- {
- addRectangle(620, 40, 10, 10, Math.random() * Math.PI * 2, false);
- return;
- }
- }
- }
- override public function update():void
- {
- super.update();
- var k:int = buttons.length;
- var i:int;
- for (i = 0; i < k; i++)
- buttons[i].update();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement