Well, I'm still not 100% sure that this is allowed, but I might as well post this for others to use...
Point-and-click movement (with size change based on perspective):
In order to use these codes, you need to have a movieclip with an instance name of "player", and the walkable area needs to be a movieclip with an instance name of "walkable".
Put the following code on the first frame (or whatever frame you are using):
var perspectiveShrink:Number = -20;
function onLoad() {
_root.createEmptyMovieClip("topStage", 0)
topStage._yscale = 1;
topStage._xscale = stage.width;
topStage._x = 0;
topStage._y = 0;
//create an empty movieclip at the top of the stage
}
function onEnterFrame() {
distance = Math.sqrt(Math.pow(topStage._x - player._x, 2)+Math.pow(topStage._y - player._y, 2))/perspectiveShrink;
if (distance > 50) distance = 50;
player._xscale = 50-distance;
player._yscale = 50-distance;
}
And this belongs on the player movieclip:
onClipEvent (mouseDown)
//This isn't really necessary, it shows if you clicked the walkable area or not
if (_root.walkable.hitTest(_root._xmouse, _root._ymouse, true ) ) {
trace ("yep" ) ;
}
if (!_root.walkable.hitTest(_root._xmouse, _root._ymouse, true ) ) {
trace ("nope" ) ;
}
}
onClipEvent (mouseDown) {
if (_root.walkable.hitTest(_root._xmouse, _root._ymouse, true ) ) {
//load these variables on every click if the player clicked on the walkable area
xMouse = _root._xmouse;
yMouse = _root._ymouse;
moveAngle = Math.atan2(yMouse - this._y, xMouse - this._x ) ;
walkX = Math.cos(moveAngle)*5;
walkY = Math.sin(moveAngle)*5;
}
}
onClipEvent (enterFrame) {
//move
if (playerWalk = true) {
this._x += walkX;
this._y += walkY;
walkDistance = Math.sqrt(((xMouse-this._x) ^ 2)+((yMouse-this._y) ^ 2) ) ;
if (walkDistance < 4) {
walkX = 0;
walkY = 0;
}
}
if (playerWalk = false) {
trace ("I'm not moving" ) ;
}
}
Note: The spaces in between closed parentheses and semicolons are to prevent them from showing up as emoticons...
Note 2: The "playerWalk" is from me trying to debug the code, and it should work if you remove it entirely. I'm not 100% sure though...