PDA

View Full Version : movie clip animation


willbill
06-05-2003, 05:36 PM
i went through the tutorial on bulding games (beginner, 38) and i was wondering how to make the movie clip do an animation for moving right or left or up or down after i press the keys for the movement. my code in the main time line for the actions layer looks like this:
watchKeyboard = new Object();
watchKeyBoard.onKeyDown = function() {
trace("a key is pressed. the key that is pressed is "+Key.getAscii());
};
Key.addListener(watchKeyBoard);
StageWidth = 600;
StageHeight = 400;
function moveStuff() {
if (Key.isDown(Key.LEFT)) {
this._x -= this.speed;
_root.man_mc;
gotoAndPlay(10);
}
if (Key.isDown(Key.RIGHT)) {
this._x += this.speed;
_root.box_mc;
gotoAndPlay(1);
}
if (Key.isDown(Key.UP)) {
this._y -= this.speed;
}
if (Key.isDown(Key.DOWN)) {
this._y += this.speed;
}
if (this._x>StageWidth+(this._width/2)) {
this._x = 0-(this._width/2);
}
if (this._x<0-(this._width/2)) {
this._x = StageWidth+(this._width/2);
}
if (this._y>StageHeight+(this._height/2)) {
this._y = 0-(this._height/2);
}
if (this._y<0-(this._height/2)) {
this._y = StageHeight+(this._height/2);
}
}
box_mc.speed = 5;
ball_mc.speed = 3;
box_mc.onEnterFrame = moveStuff;
ball_mc.onEnterFrame = moveStuff;
i = 0;
i = 0;
this.onEnterFrame = function() {
if (box_mc.hitTest(ball_mc._x, ball_mc._y)) {
newBall = ball_mc.duplicateMovieClip("ballCopy"+i, i++);
newBall._x = ball_mc._x;
newBall._y = ball_mc._y;
if (i>10) {
i = 0;
}
}
};
sorry bout the lenght... anyway if anyone could help it would be greatly appreciated. thanks

bluegel
06-23-2003, 11:03 AM
can you upload a sample fla as it would be easier to help you this way, as there is a lot of code to tredge through

thanx

spriggan
06-23-2003, 11:44 AM
Howdy Willbill (ack now you all have me doing it)

have a look at this thread

http://www.actionscript.org/forums/showthread.php3?s=&threadid=29309

it will show you how to do animation and movment with a key press.