Skip to content

Instantly share code, notes, and snippets.

@tonistiigi
Created April 7, 2012 07:37
Show Gist options
  • Save tonistiigi/2326267 to your computer and use it in GitHub Desktop.
Save tonistiigi/2326267 to your computer and use it in GitHub Desktop.
Drag movement detection + debug
//set main namespace
goog.provide('Controller');
//get requirements
goog.require('lime.Director');
goog.require('lime.Scene');
goog.require('lime.Layer');
goog.require('lime.Circle');
goog.require('lime.Label');
goog.require('lime.animation.Spawn');
goog.require('lime.animation.FadeTo');
goog.require('lime.animation.ScaleTo');
goog.require('lime.animation.MoveTo');
goog.require('lime.fill.LinearGradient');
// entrypoint
var angle;
Controller.start = function(){
var director = new lime.Director(document.body,1024,768),
scene = new lime.Scene(),
target = new lime.Layer().setPosition(512,384),
circle = new lime.Circle().setSize(300,300).setFill(60,60,60),
circle2 = new lime.Circle().setSize(250,250).setFill(92,92,92);
target.appendChild(circle);
target.appendChild(circle2);
scene.appendChild(target);
var box = new lime.Sprite().setSize(200, 10).setPosition(200,200).setFill(new lime.fill.LinearGradient().setDirection(0,0,1,0).addColorStop(.4,'#c00').addColorStop(.6, '#00c'));
scene.appendChild(box);
director.makeMobileWebAppCapable();
//add some interaction
goog.events.listen(circle2,['mousedown','touchstart'],function(e){
drag = e.startDrag(false, new goog.math.Box(-90, 90, 90, -90));
move = new lime.animation.MoveTo(0,0);
e.swallow(['mouseup','touchend','touchcancel'],function(){
this.runAction(move);
});
goog.events.listen(drag, lime.events.Drag.Event.MOVE, function(){
pos = circle2.getPosition();
posX = pos.x;
posY = pos.y;
angle = goog.math.angle(posX, posY, 0, 0);
box.setRotation(-angle);
});
});
// set current scene active
director.replaceScene(scene);
}
//this is required for outside access after code is compiled in ADVANCED_COMPILATIONS mode
goog.exportSymbol('Controller.start', Controller.start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment