View Full Version : [AS2] Click to move
Thimbletack
04-22-2009, 11:02 PM
I am trying to make a game, an mmorpg in which you click to move similair to in runescape or club penguin and other games. So how would I do this? I think I would want about 3 things to happen when they click on a spot. I want the character to move to that spot at a defined speed, I want it to play the character moving animation, and I want it to play a little movie clip where they clicked. How would I do this? Also I want to have customizable characters so to do that would I have to make a walking animation for each different pair of pants they can wear or is there some easy way to do it so that it just puts the pants over the character. same for shirts and ect.
That last question would be nice but its ok if all you know is the first part. that is all I am really worried about at the moment.
Thanks for the help,
Thimbletack
pradvan
04-23-2009, 07:45 PM
Paste this on frame 1. Create a movieclip and give it an instance name of "my_mc"
import mx.transitions.Tween;
import mx.transitions.easing.*;
var xpos:Number;
var ypos:Number;
onMouseDown=function () {
xpos=this._xmouse;
ypos=this._ymouse;
var xTween = new Tween(my_mc, "_x", Regular.easeInOut, my_mc._x, xpos, 1.5, true);
var yTween = new Tween(my_mc, "_y", Regular.easeInOut, my_mc._y, ypos, 1.5, true);
}
Thimbletack
04-23-2009, 11:38 PM
Thanks but I have a couple more questions.
1. How can I make it play the mc while he is moving?
2. How can I make it so he stops wherever he is in the mc when he is done moving?
3.Is there a way so i can change it so its not so slidy? It kind of seems like hes on ice. I was looking more towards going straight to the spot.
4. Can I edit the speed at which he is moving?
5. How could i make it so that wherever you click it plays an mc there?
Thanks for all the help,
Thimbletack
pradvan
04-24-2009, 03:33 AM
Do you understand that code at all?
Thimbletack
04-27-2009, 01:05 AM
A little bit... I get that you are importing tweening and easing, You declare two variables for X and Y. and on the click it moves the character towards the x and y. I guess the Regular.easeInOut is what gives the sliding i guess? and i am assuming the 1.5 is speed? I know programming pretty well its mainly I don't know all of the stuff you can do to make movie clips do things. so for the mc on click would i do something like:
var clickMC_X = new movieClip (click_mc, "_x", click_mc._x, xpos);
or something like that and do the same for Y?
and then do something like:
my_mc.stop();
inside some other code or something. I understand coding I just don't know how it all works with flash. like how to insert code into a movie clip, and such. Anyway thanks for the help so far again. If you could show me how to make it so this stuff works that would be great. Also was I right about the whole 1.5 being speed and Regular.easInOut being the slidyness?
Thanks
Thimbletack
bluemagica
04-27-2009, 05:40 AM
err, you are kindof right! But i won't recommend using tween for this!
1.5 is not the speed, but the time it should take to complete the tween! But that would mean, the speed will vary with distance which will be really odd, instead you should use some custom code.
onClick = function()
{
mX = mouse._x;
mY = mouse._y;
}
if(Math.abs(this._x-mX)>=4)
{
if(this._x>mX) //this is lying right to where mouse clicked
this._x-=4; //move left, since "this" is one right
else
this._x+=4;
}
if(Math.abs(this._y-mY)>=4)
{
if(this._y>mY)
this._y-=4;
else
this._y+=4;
}
PS: I haven't coded in as2 for quite some time, so this may be wrong code, but should give you an idea!
also read the adobe livedocs to understand what are tweens and such, don't try to guess on your own!
Thimbletack
04-27-2009, 11:01 PM
Well, I would alter that code if i could but i haven't done much game programming yet as i said. I know basics like object oriented programming, and such. but I don't know all of the actionscript built in commands. That code didn't really work. I really don't know how you wrote it though. anyone got any ideas?
Thimbletack
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.