Go To Different Spots
| Category | : Flash | Views | : 22748 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : go-to-different-spots.zip | ||
| Result | : See the result | ||||
var tga = (map._y - destY) / (map._x - destX);
Here we calculate the tangent to get the angle we need to move.
var ang = (Math.atan(tga) * 180) / Math.PI;
Using the function Math.atan(tangent) we get the radians, but we need the angle so we multiply the radians with 180/Pi.
if (map._x >= destX)
{
If the destination coordinate of the map is to the right.
map._x -= speed * Math.cos((ang) * Math.PI / 180);
map._y -= speed * Math.sin((ang) * Math.PI / 180);
Move the map in both coordinates using vector math for the amount of pixels in _x and _y.
}
else if (map._x <= destX)
{
If the destination coordinate of the map is to the left.
map._x += speed * Math.cos((ang) * Math.PI / 180);
map._y += speed * Math.sin((ang) * Math.PI / 180);
Move the map.
}
NA.onRelease = function()
{
Event handler for this button release
_root.destX = 650
_root.destY = 350
Set a new coordinate for the destination and that makes the Map scroll.The only thing that changes on other button is the coordinates
