Another one of those AS2 help threads.

Started by: FoShizzle | Replies: 13 | Views: 885

FoShizzle
2

Posts: 2,524
Joined: Jun 2007
Rep: 10

View Profile
Jan 24, 2010 11:25 AM #540158
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
2

Posts: 9,168
Joined: Oct 2005
Rep: 10

View Profile
Jan 24, 2010 12:28 PM #540166
i can't help you unless you post your script.
FoShizzle
2

Posts: 2,524
Joined: Jun 2007
Rep: 10

View Profile
Jan 24, 2010 12:54 PM #540167
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
2

Posts: 9,168
Joined: Oct 2005
Rep: 10

View Profile
Jan 24, 2010 1:33 PM #540177
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
2

Posts: 2,524
Joined: Jun 2007
Rep: 10

View Profile
Jan 24, 2010 1:39 PM #540183
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
2

Posts: 9,168
Joined: Oct 2005
Rep: 10

View Profile
Jan 24, 2010 1:56 PM #540190
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
2

Posts: 2,524
Joined: Jun 2007
Rep: 10

View Profile
Jan 24, 2010 2:00 PM #540191
Doesn't work .
Scarecrow
2

Posts: 9,168
Joined: Oct 2005
Rep: 10

View Profile
Jan 25, 2010 10:22 AM #540476
do you have a vcam on the stage with the instance name "vcam"

because you should
FoShizzle
2

Posts: 2,524
Joined: Jun 2007
Rep: 10

View Profile
Jan 25, 2010 11:26 AM #540484
Okay wait, so I put that code on every frame in the movieclip?
Scarecrow
2

Posts: 9,168
Joined: Oct 2005
Rep: 10

View Profile
Jan 25, 2010 11:38 AM #540485
no, put it on the frame of the main movie

along with stop(); and such
FoShizzle
2

Posts: 2,524
Joined: Jun 2007
Rep: 10

View Profile
Jan 25, 2010 11:41 AM #540486
stop(); at the end of that right?

Well I did that still doesn't work :c
Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Jan 26, 2010 12:24 AM #540647
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
2

Posts: 9,168
Joined: Oct 2005
Rep: 10

View Profile
Jan 26, 2010 1:49 AM #540669
i already got it to work for him he didn't know what instance names were
FoShizzle
2

Posts: 2,524
Joined: Jun 2007
Rep: 10

View Profile
Jan 26, 2010 8:57 AM #540786
Quote from Scarecrow
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: