-
[AS2] Point and Click Movement
Okay, so I'm completely new to flash and I'm having a bit of trouble getting around the learning curve. What I'm trying to do right now is script my game so that the player has to press the 'M' key, then select a position on the screen to move to. Well, teleport rather-- the player won't be moving the piece as much as he will be placing it.
So...how do I go about doing this?
Thanks in advance!
-
Senior Member
So which part of this are you having trouble with? Detecting when player presses M key? Placing object on the screen at coordinates of mouse cursor?
-
Both, but the 'M' part is fairly simple, right? Its just a variable set?
So, I have a clue as to how to set the M, but I have no idea as to the mouse cursor bit. =\
-
Senior Member
To place movie clip where mouse is clicked, first put instance of movie clip on the stage. Give it instance name "mymc". Now select the keyframe (not movie clip instance but the frame) and write code there:
PHP Code:
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
mymc._x = _xmouse;
mymc._y = _ymouse;
};
Mouse.addListener(mouseListener);
-
Ah, excellent! Thank you! Now, do I put that inside the function of onClipEvent (keypress 'M') or something completely different?
-
Senior Member
No, that was suppose to be separate from clipEvents and my example code does not require M to be pressed. If you have clipEvent to detect M key and you want to add this code there too, you probably need to rewrite it to something like this:
this._x = _root._xmouse;
this._y = _root._ymouse;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|