javascript - How to calculate to position x, y considering the scale -
for example need move point: [50, 50], , have stage scale of 10.4, how calculate position considering scale formula?
$('#bphonesearch').click(function(e){ e.preventdefault(); node.nextxpoint = (stage.width() / 2 - pos.x); node.nextypoint = (stage.height() / 2 - pos.y); node.status = 'moving'; }); on click i'am getting end point need reach(it in center) , in frameanimation function:
if(node.status == 'moving') { var dx = (stage.x() - node.nextxpoint); var dy = (stage.y() - node.nextypoint); var dist = math.sqrt(dx * dx + dy * dy); console.log(dist); if(dist < 5) { stage.x(node.nextxpoint); stage.y(node.nextypoint); node.status = ''; } else { var angle = math.atan2(dy, dx); var speedx = -math.cos(angle) * 6; var speedy = -math.sin(angle) * 6; stage.x(stage.x() + speedx); stage.y(stage.y() + speedy); } } i'am doing moving animation, works ok, when scale stage, position getting wrong, question put scale calculation.
how stage scale: stage.getscalex(), stage.getscaley()
i'm not sure got question correctly seems bit simple. missing something?
scale = 10.4; // scale posxscaled = posx * scale; //posx 50 in example positions[0] posyscaled = posy * scale; // positions[1] edit
i think need add scale calculation here:
var dx = (stage.x() - node.nextxpoint) * scale; var dy = (stage.y() - node.nextypoint) * scale; you might need update conditional:
if(dist < 5 * scale)
Comments
Post a Comment