ForumsProgramming ForumWhy is my code doing this!? (as2)

1 5991
mightybob
offline
mightybob
360 posts
Peasant

Here is my code: (as2)


onClipEvent(load) {
var ground:MovieClip = _root.ground2;
var grav:Number = 0;
var gravity:Number = 1.5;
var speed:Number = 13;

var slideSpeed:Number = 12;

var maxJump:Number = -25;
var maxRampJump:Number = -33;
var maxSpringBounce:Number = -37;
var touchingGround:Boolean = false;
var hittingWall:Boolean = false;
var moving:Boolean;
var jumpAudio:Sound = new jumpSound;
}

onClipEvent(enterFrame) {
_y += grav;
grav += gravity;

((frames_to_go-frames_passed)*starting_x_difference)+target_x

while (ground.hitTest(_x, _y, true))
{
_y -= gravity;
grav = 0;
}

if (ground.hitTest(_x, _y+5, true))
{
touchingGround = true;
}

else {
touchingGround = false;
}

if (Key.isDown(Key.RIGHT) && !Key.isDown(Key.DOWN))
{
_x += speed;
_xscale = 100;
gotoAndStop(2);
}

if (Key.isDown(Key.LEFT) && !Key.isDown(Key.DOWN))
{
_x -= speed;
_xscale = -100;
gotoAndStop(2);
}


//////////////

if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN))
{
_x += slideSpeed;
_xscale = 100;
gotoAndStop(5);
}

if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN))
{
_x -= slideSpeed;
_xscale = -100;
gotoAndStop(5);
}

if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN) && slideSpeed > 0)
{
slideSpeed -= 0.2;
}

if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN) && slideSpeed > 0)
{
slideSpeed -= 0.2;
}

if(!Key.isDown(Key.DOWN))
{
slideSpeed = 12;
}

////////////////////

if (!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.UP))
{
gotoAndStop(1);
moving = false;
}

if (Key.isDown(Key.UP) && touchingGround)
{
grav = maxJump;
gotoAndStop(3);
}

if (ground.hitTest(_x+(_width/2), _y-(_height/2), true))
{
_x -= speed;
gotoAndStop(1);
hittingWall = true;
}

else {
hittingWall = false;
}

if (ground.hitTest(_x-(_width/2), _y-(_height/2), true))
{
_x += speed;
gotoAndStop(1);
hittingWall = true;
}

else {
hittingWall = false;
}

if (ground.hitTest(_x, _y-(height), true))
{
grav = 3;
hittingWall = true;
}

else {
hittingWall = false;
}


if (hitTest(_root.spring)==true)
{
grav = maxSpringBounce;
gotoAndStop(4);
_root.spring.gotoAndPlay(2);
}

if (hitTest(_root.spring2)==true)
{
grav = maxSpringBounce;
gotoAndStop(4);
_root.spring2.gotoAndPlay(2);
}

if (hitTest(_root.spring3)==true)
{
grav = maxSpringBounce;
gotoAndStop(4);
_root.spring3.gotoAndPlay(2);
}

if(hitTest(_root.right_ramp)==true && Key.isDown(Key.RIGHT))
{
grav = maxRampJump;
}

if(hitTest(_root.right_ramp2)==true && Key.isDown(Key.LEFT))
{
grav = maxRampJump;
}

if(hitTest(_root.ramp3)==true && Key.isDown(Key.RIGHT))
{
grav = -45;
}

if(hitTest(_root.ramp4)==true && Key.isDown(Key.LEFT))
{
grav = -20;
}

if(hitTest(_root.ramp5)==true && Key.isDown(Key.LEFT))
{
grav = -20;
}

if(hitTest(_root.ramp6)==true && Key.isDown(Key.LEFT))
{
grav = -20;
}

if(hitTest(_root.leftWallJump)==true && Key.isDown(Key.RIGHT))
{
//gotoAndStop(6);
if(!Key.isDown(Key.UP))
{
grav = 0;
}

if(Key.isDown(Key.UP))
{
grav = -15;
}
}

if(hitTest(_root.wallClimb2)==true && Key.isDown(Key.RIGHT))
{
//gotoAndStop(6);
if(!Key.isDown(Key.UP))
{
grav = 0;
}

if(Key.isDown(Key.UP))
{
grav = -15;
}
}

}

And it keeps making my player (with instance of char) stopping at the last frame inside itself, and it wont stop now matter how many gotoAndStop(1)'s i put in there and it's driving me nuts!

  • 1 Reply
weirdlike
offline
weirdlike
1,299 posts
Prince

I think you need this

char_MC.gotoAndStop(1);

unless you are coding on the object itself and not the main timeline

this.gotoAndStop(1);

Showing 1-1 of 1