This tutorial demonstrates a variety of
ways to use the mouse and keyboard to control an object controls.This
tutorial demonstrates a variety of ways to use the mouse

and keyboard to
control an object controls.This tutorial demonstrates a variety of ways to
use the mouse
onClipEvent (load)
{
// this example demonstrates an object moving in the
x axis
// define a variable which will control the speed
// of this object
// Note : > number moves slower < number moves faster
speed=10;
}
onClipEvent (enterFrame) {
// find the distance between the
mouse and the spaceship
// then calculate a fraction of that distance
// by dividing by speed
xdist = (_root._xmouse-_x)/speed;
// update the x position of this object
_x=_x+xdist;
// collision detection with right edge
// if this object
if(_x>(400-(_width/2)))
{
_x=(400-(_width/2));
}
// collision detection with left edge
if(_x<(_width/2))
{
_x=(_width/2);
}
}
Challenge
The code above allows the
spaceship to follow the mouse only in the X axis. Try modifying the code to
allow the spaceship to follow the mouse in both the X and Y axis.
[2] Follow the Cursor
and keyboard to control an object controls.This tutorial
demonstrates a variety of ways to use the mouse and keyboard to control an
object controls.This tutorial demonstrates a variety of ways to use the
mouse and keyboard to control an object controls.This tutorial
demonstrates a variety of ways to use the mouse and keyboard to control an
object controls.
|