Copy link to clipboard
Copied
I have created a piece of code, based on code from this tutorial
Design simple interactive content |
which makes the object turn at 180 degree following the cusor movements.
I like to ask if anybody can tell me what code I should use, if I would like the object to follow the cursor around the stage ?
I have the following code in ActionScript 3,
stage.on('stagemousemove', function(e){
var radians = Math.atan2(e.localY - _this.test.y, e.localX - _this.test.x);
var degrees = radians * (180 / Math.PI);
_this.test.rotation = degrees - 180;
});
Also if anybody could tell me where to find ActionScript code in general and if possible examples of ActionScript code and functions.
Thanks
that's not as3. it looks like createjs and you're missing the definition for _this.
it's also not clear what you want. if you want _this.test to 'tween' to the cursor use something like:
var _this=this;
var speed = .95; // 0 to 1
var fI;
stage.on('stagemousemove', function(e){
var radians = Math.atan2(e.localY - _this.test.y, e.localX - _this.test.x);
var degrees = radians * (180 / Math.PI);
_this.test.rotation = degrees - 180;
_this.test.x = speed*_this.test.x+(1-speed)*e.localX;
_this.test.y = speed*_
...Copy link to clipboard
Copied
that's not as3. it looks like createjs and you're missing the definition for _this.
it's also not clear what you want. if you want _this.test to 'tween' to the cursor use something like:
var _this=this;
var speed = .95; // 0 to 1
var fI;
stage.on('stagemousemove', function(e){
var radians = Math.atan2(e.localY - _this.test.y, e.localX - _this.test.x);
var degrees = radians * (180 / Math.PI);
_this.test.rotation = degrees - 180;
_this.test.x = speed*_this.test.x+(1-speed)*e.localX;
_this.test.y = speed*_this.test.y+(1-speed)*e.localY;
clearInterval(fI);
fI=setInterval(f.bind(e),50);
});
function f(){
_this.test.x = speed*_this.test.x+(1-speed)*this.localX;
_this.test.y = speed*_this.test.y+(1-speed)*this.localY;
}
Copy link to clipboard
Copied
Thanks, and yes you are right, it is createjs 🙂
Here is the complete code for the rotation of an object, posted in my my question, if anybody like to try it out.
stage.enableMouseOver(30);
var _this = this;
stage.on('stagemousemove', function(e){
var radians = Math.atan2(e.localY - _this.test.y, e.localX - _this.test.x);
var degrees = radians * (180 / Math.PI);
_this.test.rotation = degrees - 90;
});
Copy link to clipboard
Copied
you're welcome.