• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Converting an animation made in actionscript to HTML5 Problems

Community Beginner ,
Oct 16, 2022 Oct 16, 2022

Copy link to clipboard

Copied

This is my code, I am getting no errors but the eye are not moving.

var root = this;
var container, var1, var2, var3, radius1, radius2, eyeR, eyeL;
var shapes = [];

function main()
{
root.stop();
container = root.container;
eyeR = root.eyeR;
eyeL = root.eyeL;
container.mouseChildren = false;
eyeR.mouseChildren = false;
eyeL.mouseChildren = false;
stage.enableMouseOver(20);
container.on("mouseMove", mouseMoved);
}

 

function mouseMoved(e)
{
var1 = e.stageY - 270 / stage.scaleY;
var2 = e.stageX - 380 / stage.scaleX;
var3 = e.stageX - 580 / stage.scaleX;
radius1 = Math.atan2(var1,var2);
radius2 = Math.atan2(var1, var3);
eyeR.setTransform(580,270,1,1,radius2);
eyeL.setTransform(380,270,1,1,radius1);
}

 

main();

 

 

This is how I made it work in P5.js and ActionScript for refernce on how it should work.

https://editor.p5js.org/JWNimble/sketches/4-cBgdHkH

 ActionScript Code

stage.addEventListener("mouseMove", arjun);
function arjun(e:MouseEvent):void
{
var var1 = mouseY - eyeR.y;
var var2 = mouseX - eyeR.x;
var radiusR = Math.atan2(var1,var2);
var degreeR = radiusR / (Math.PI / 180);
eyeR.rotation = degreeR;

var var3 = mouseY - eyeL.y;
var var4 = mouseX - eyeL.x;
var radiusR1 = Math.atan2(var3,var4);
var degreeR1 = radiusR1 / (Math.PI / 180);
eyeL.rotation = degreeR1;
}

Views

187

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 16, 2022 Oct 16, 2022

Copy link to clipboard

Copied

use console.log() to debug.  for example:

 

ar root = this;
var container, var1, var2, var3, radius1, radius2, eyeR, eyeL;
var shapes = [];

function main()
{
root.stop();
container = root.container;
eyeR = root.eyeR;
eyeL = root.eyeL;
container.mouseChildren = false;
eyeR.mouseChildren = false;
eyeL.mouseChildren = false;
stage.enableMouseOver(20);
container.on("mouseMove", mouseMoved);
}

 

function mouseMoved(e)
{
var1 = e.stageY - 270 / stage.scaleY;
var2 = e.stageX - 380 / stage.scaleX;
var3 = e.stageX - 580 / stage.scaleX;
radius1 = Math.atan2(var1,var2);
radius2 = Math.atan2(var1, var3);
eyeR.setTransform(580,270,1,1,radius2);
eyeL.setTransform(380,270,1,1,radius1);

 

console.log(eyeR,radius2);
}

 

main();

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 16, 2022 Oct 16, 2022

Copy link to clipboard

Copied

I have been, it returns no errors though

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 16, 2022 Oct 16, 2022

Copy link to clipboard

Copied

what's a portion of the console output from the code i suggested?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 16, 2022 Oct 16, 2022

Copy link to clipboard

Copied

i just tested your code and you can see from the console.log() that mouseMoved is not being called.  meaning your "mouseMove" listener is problematic.  and in fact there is no "mouseMove", though "mousemove" would be a better try, but it doesn't exist either.  

 

check the stage.  it has a "stagemousemove" listener you can use:

 

stage.addEventListener("stagemousemove",mouseMoved.bind(this));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 17, 2022 Oct 17, 2022

Copy link to clipboard

Copied

you have locked my previous post on this but I still would like to figure out what is going one with the rotational angles of the eyes, now that it is actually rotating. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 17, 2022 Oct 17, 2022

Copy link to clipboard

Copied

I think that Math.atan2 works in radians, and setTransform works in degrees.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 17, 2022 Oct 17, 2022

Copy link to clipboard

Copied

LATEST

@Colin Holgate, is correct.  you have to convert from radians to degrees:

 

eyeL.setTransform(380,270,1,1,180*radius1/Math.PI);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines