RTS -need help
- 2g4gzus
-
2g4gzus
- Member since: Mar. 20, 2006
- Offline.
-
- Forum Stats
- Member
- Level 04
- Blank Slate
MMkay, i'm just starting work on a real-time strategy game, done with actionscript 2.0. I haven't done a whole lot of work on it yet, but i have encountered one problem so far, and expect to come across a couple more before it's done. Right now, the thing that's buggin me is that when a unit is selected, i can't get him to move. I don't need the actionscript for manouevering, just enough to get him to move to the mouse when i click.
This is what I have right now, i haven't really tried too much yet, but what you need to know is that 'conscript' is a movie clip which will be duplicated into the units the players use. The duplicated movie clips are called ["c" + _root.cc].
onClipEvent(load){
if(_name != "conscript"){
this._x = _root.barracks._x
this._y = _root.barracks._y
}
}
on(press){
// now what the hell goes here?
}
thanks to anyone who helps.
- Cojones893
-
Cojones893
- Member since: Mar. 9, 2003
- Offline.
-
- Forum Stats
- Member
- Level 22
- Blank Slate
function onMouseDown(){
storeX = _root._xmouse;
storeY = _root._ymouse;
}
something like that will store then _x and _y value of the mouse when clicked. It's up to you to apply it. You might also want to start on a much easier game, RTS's get pretty complex and if you are having simple movement problems then I guarentee you'll encounter more. But goodluck to you.
- JeremysFilms
-
JeremysFilms
- Member since: Feb. 18, 2005
- Offline.
-
- Forum Stats
- Member
- Level 18
- Blank Slate
Put this in the frame:
_root.onMouseDown = function() {
mx = _root._xmouse;
my = _root._ymouse;
};
_root.onEnterFrame = function() {
if (mx < _root.barracks._x) {
dx = _root.barracks._x - mx;
} else {
dx = mx - _root.barracks._x;
}
moveSpeedx = dx / 10;
if (mx < _root.barracks._x) {
_root.barracks._x -= moveSpeedx;
} else {
_root.barracks._x += moveSpeedx;
}
if (my < _root.barracks._y) {
dy = _root.barracks._y - my;
} else {
dy = my - _root.barracks._y;
}
moveSpeedy = dy / 10;
if (my < _root.barracks._y) {
_root.barracks._y -= moveSpeedy;
} else {
_root.barracks._y += moveSpeedy;
}
};
You're gonna want to trash the on(press) handler and put the onLoad clipevent handler on the frame, obviously changing it from a clipevent to a function.
In my opinion, you should put all code on the frame, you have much greater control over what goes on.

