PDA

View Full Version : Another one of those AS2 help threads.



FoShizzle
01-24-2010, 04:25 AM
So I'm trying to make a good game engine, and I need some help with it.
First off, I don't get any errors on it.. but.. When my character moves to the left or right, the animation keeps on looping. I've already put stop(); on the movie clips, but it doesn't seem to work.. halp?

heres an example: http://filebox.me/view/8kdh826na

(left arrow and right arrow to move) (no duh)

Scarecrow
01-24-2010, 05:28 AM
i can't help you unless you post your script.

FoShizzle
01-24-2010, 05:54 AM
Hi my bad .


onClipEvent (load) {
speed = 12;
}
onClipEvent (enterFrame) {
if ((Key.isDown(Key.RIGHT)) && (jumping == false)) {
this.gotoAndStop(2);
}
if ((Key.isDown(Key.LEFT))&& (jumping == false)) {
this.gotoAndStop(3);
}
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
}
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
}
if (Key.isDown(65)) {
this.gotoAndStop(4);
}
if (Key.isDown(83)) {
this.gotoAndStop(6);
}
}
onClipEvent (load) {
y_start = _y;
jumping = false;
jumpspeed = 0;
}
onClipEvent (enterFrame) {
if (jumping) {
_y += jumpspeed;
jumpspeed += 1;
if (_y>=y_start) {
_y = y_start;
jumping = false;
}
} else {
if (Key.isDown(Key.SPACE)) {
jumping = true;
jumpspeed = -14;
this.gotoAndStop(5);
}
}
}

Scarecrow
01-24-2010, 06:33 AM
you haven't got any code telling it to go back to frame one.

try


onClipEvent (load) {
speed = 12;
}
onClipEvent (enterFrame) {
if (!walkingleft && !walkingright && !jumping){ //added this
this.gotoAndStop(1); //added this
} //added this
if ((Key.isDown(Key.RIGHT)) && (jumping == false)) {
walkingright = true; //added this
this.gotoAndStop(2);
}else{ //added the else
walkingright = false; //added this
} //added this
if ((Key.isDown(Key.LEFT))&& (jumping == false)) {
this.gotoAndStop(3);
walkingleft = true; //added this
}else{ //added the else
walkingleft = false; //added this
} //added this
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
}
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
}
if (Key.isDown(65)) {
this.gotoAndStop(4);
}
if (Key.isDown(83)) {
this.gotoAndStop(6);
}
}
onClipEvent (load) {
y_start = _y;
jumping = false;
jumpspeed = 0;
}
onClipEvent (enterFrame) {
if (jumping) {
_y += jumpspeed;
jumpspeed += 1;
if (_y>=y_start) {
_y = y_start;
jumping = false;
}
} else {
if (Key.isDown(Key.SPACE)) {
jumping = true;
jumpspeed = -14;
this.gotoAndStop(5);
}
}
}

FoShizzle
01-24-2010, 06:39 AM
I think I love you.
ALSO, how can I attach some kind of.. Vcam onto the walking stick? Let's say I put him in some town, I want him to walk in the center, but the background moves. Or create some kind of effect that will show that.
How do I do dat

Scarecrow
01-24-2010, 06:56 AM
better still, i have a smooth follow i've been using

put this on frame


onEnterFrame = function() {
//On every frame run this code
camerafollow(player);
//run the camera function with "player" as the value of "obj" to make the camera follow the movieclip "player"... using this method you can make the camera follow anything with an instance name.
};

function camerafollow(obj) {
//create a function called camerafollow with on input variable
xcamDist = vCam._x-obj._x;
ycamDist = vCam._y-obj._y;
//find the distance between the vcam and the variable object
vCam._x -= xcamDist/7;
vCam._y -= ycamDist/7;
//move the vCam towards the object at a speed determined by the distance between them, divided by ten
}

if it doesn't work you probably already have an onEnterFrame function and you just need to merge yours with mine

FoShizzle
01-24-2010, 07:00 AM
Doesn't work .

Scarecrow
01-25-2010, 03:22 AM
do you have a vcam on the stage with the instance name "vcam"

because you should

FoShizzle
01-25-2010, 04:26 AM
Okay wait, so I put that code on every frame in the movieclip?

Scarecrow
01-25-2010, 04:38 AM
no, put it on the frame of the main movie

along with stop(); and such

FoShizzle
01-25-2010, 04:41 AM
stop(); at the end of that right?

Well I did that still doesn't work :c

Scorpioxxx
01-25-2010, 05:24 PM
Right, for the vcam thing, try this.

Put the vcam on the stage and add the following code to the frame:

_root.VCAMINSTANCENAME._x = _root.PLAYERINSTANCENAME._x
_root.VCAMINSTANCENAME._y = _root.PLAYERINSTANCENAME._y

If i ****ed that up, just put the vcam on the stage and at the end of the vcam code add this:

onClipEvent (enterFrame) {
this._x = _root.PLAYERINSTANCENAME._x
this._y = _root.PLAYERINSTANCENAME._y
}

It should work with the first one but this is off the top of my head and AS2 and AS3 are kinda merging into one a bit.

Scarecrow
01-25-2010, 06:49 PM
i already got it to work for him he didn't know what instance names were

FoShizzle
01-26-2010, 01:57 AM
i already got it to work for him he didn't know what instance names were

Yes I did, I told you what it was after thinking about it
:Nooooooo: