Eyes Follow Mouse & Random Movement - HTML5
I'm trying to achieve a couple of effects in Animate using HTML5 to create interactive aliens and random spaceships with the kids. I've pasted in what I've found so far and have tried many many times going round in circles to get these to work with no joy.
Eyes Follow Mouse
Looking for some code to create (one or many) 'eyes' to follow the cursor around the canvas.
Have searched on here for similar questions and tried some suggested solutions but not working.
Also tried this tutorial that uses the following code.
I'm guessing this is Actionscript that doesn't exist in HTML5 Canvas?
var eyeArray:Array = [eye1, eye2];
stage.addEventListener(MouseEvent.MOUSE_MOVE, allEyesOnMe);
function allEyesOnMe(event:MouseEvent):void {
for(var eye:String in eyeArray {
var mousediff_a:Number = mouseY - eyeArray[eye].y;
var mousediff_b:Number = mouseX - eyeArray[eye].x;
var radians = Math.atan2(mousediff_a,mousediff_b);
var degrees = radians / (Math.PI / 180);
eyeArray[eye].rotation = degrees;
}
}
Random Movement at Random Time
Another AS tutorial that I just cannot get working in HTML5.
I'd like to do something like in the tutorial where a movieclip randomly moves around the screen (within set parameters). But would also like to incorporate this happening at random times (within set parameters - e.g sometimes it might move after 2 seconds, sometimes after 8 seconds). And tweening to a random size each time (within parameters) would be the icing on the cake!
var randX;
var randY;
function randomNumbers(){
randX = Math.floor(Math.random()*800);
randY = Math.floor(Math.random()*500);
moveMe();
}
randomNumbers();
function moveMe(){
sym.$("myRect").animate({left: randX, top: randY},1000, randomNumbers);
}
There are so many amazing Actionscript tutorials online but some just won't work within the HTML5 environment. It's a shame there's no one doing these kind of tutorials for Animate HTML5.
