Image rotates when mouse moves

 

The purpose is to rotate an eye when mouse moves. We 'll use a script.
I suppose you know well how to create objects, thus I wont insist on.

⇒ animation ⇐

Download images 

Creating Objects

1 - Set up movie size 640x480 and background color #009900.
Any Frame Rate.

2 - Put right eye : Menu Insert / Image. Follow images

   

3 - Put left eye : Menu Insert / Image. Follow images

   

4 - Put cursor : Menu Insert / Image. Follow images

   

4 - Draw a rectangle. ( alpha = 127 ). Follow images

   

Check out anchor points.

Script

In Outline, select scene, get in Expert Mode. Enter script :

onLoad ()
{
      Mouse.hide();
      
      left = 260;
      top = 140;
      right = 620;
      bottom = 460;
      curseur.startDragLocked(left, right, top, bottom);
// anchor point : center
      Xc_g = _root.oeilG._X + ( _root.oeilG._width / 2);
      Yc_g = _root.oeilG._Y + ( _root.oeilG._height / 2);
      Xc_d = _root.oeilD._X + ( _root.oeilD._width / 2);
      Yc_d = _root.oeilD._Y + ( _root.oeilD._height / 2);
}

onEnterFrame()
{ // angles
      deltaXg = _root.curseur._X - Xc_g;
      deltaYg = _root.curseur._Y - Yc_g;
      if ( deltaXg == 0 ) angleG = 90;
      else angleG = Math.atandeg( deltaYg / deltaXg );
      deltaXd = _root.curseur._X - Xc_d;
      deltaYd = _root.curseur._Y - Yc_d;
      if ( deltaXd == 0 ) angleD = 90;
      else angleD = Math.atandeg( deltaYd / deltaXd );
// angle rotation
      _root.oeilG._rotation = angleG;
      _root.oeilD._rotation = angleD;
}

This example is quite simple. To move all over the scene, you 'll need to manage delta__ sign.

 


Si vous aimez le site

 

Select a language if you need :


Page chargée en 0.046 sec.

Dernière Modification : Mer 25 Janvier 2017 8:56
Copyright © 1999-2017 Jean-Paul Molina Tous droits réservés.

to Google