ForumsProgramming Foruma problem with cs4 action script 2

3 2978
nananya
offline
nananya
3 posts
Nomad

function a()
{
this._y -= 2;
if((man1._y - (this._y -man1._height) < 5) && (man1._x >= this._x-(man1._width/2)) && (man1._x <= this._x+200+(man1._width/2)) )
{
man1._y == this._y - man1._height;
man1.onPlatform = true;
}
else
{
man1.onPlatform = false;
}
if ((man1._y == this._y - man1._height))
{
trace(man1.onPlatform);
man1._y -= 2;
}
if ((man1._x == this._x -(man1._width/2)) && man1.onPlatform == true)
{
man1._xlmax = true;
}
if ((man1._x+man1._width == this._x + 200+(man1._width/2)) && man1.onPlatform == true)
{
man1._xrmax = true;
}
if (this._y < 0)
{
this.removeMovieClip();
}
}
attachMovie(&quotlatform",&quotlatform0",1);
platform0._x = 300;
platform0._y = 200;
platform0.onEnterFrame = a;
attachMovie(&quotlatform",&quotlatform1",2);
platform1._x = 100;
platform1._y = 600;
platform1.onEnterFrame = a;


This is a function which detect the character got landed on another platform,from the platform above,jump down to another platform.
But when i testing it the character will pass through the another platform below.
So i want to know what is wrong.
Can anyone point it out for me?
Thank you.
  • 3 Replies
nananya
offline
nananya
3 posts
Nomad

The problem have been solved.
But new problem came out.
why the character will slide along the next platform and even gone out of the platform.

uTime = 0;
function man()
{
man1.onKeyUp=man1KeyUp;
man1.onKeyDown=man1KeyDown;
man1.onEnterFrame=man1EnterFrame;
Key.addListener(man1);
}
function man1EnterFrame(){
if(man1.left && man1._xlmax != true && man1.onPlatform == true)
{
man1.gotoAndStop("left&quot;
man1._x= man1._x-5;
man1.facing = "left";
}
else if(man1.right && man1._xrmax != true && man1.onPlatform == true)
{
man1.gotoAndStop("right&quot;
man1._x= man1._x+5;
man1.facing = "right";
}
if ((man1.jump == true && man1.onPlatform == true && uTime< 4) || (man1.onPlatform == false && man1.jumpUp == true && uTime <= 3)) jump();
else drop();
}
function man1KeyDown()
{
k=Key.getCode();
if(k==Key.LEFT) man1.left=true;
else if(k==Key.RIGHT) man1.right = true;
else if(k==Key.SPACE) {man1.jump=true; man1.jumpUp = true;}
}
function man1KeyUp()
{
k=Key.getCode();
if(k==Key.LEFT) man1.left=false;
else if(k==Key.RIGHT) man1.right=false;
else if(k==Key.SPACE) man1.jump = false;
}
function jump()
{
man1.onKeyUp=null;
man1.onKeyDown=null;
man1.onPlatform = false;
man1._xlmax = false;
man1._xrmax = false;
if ( man1.facing == "left" && uTime < 4)
{
man1._y -= 5;
man1._x -= 5;
uTime = uTime+1;
}
else if ( man1.facing == "right" && uTime < 4 )
{
man1._y -= 5;
man1._x += 5;
uTime = uTime+1;
}
}
function drop()
{
man1.jumpUp = false;
if (uTime >= 4 && man1.facing == "right&quot
{
man1._y += 5;
man1._x += 3;
uTime = uTime+1;
}
else if (uTime >= 4&& man1.facing == "left&quot
{
man1._y += 5;
man1._x -= 3;
uTime = uTime+1;
}
if (man1.onPlatform == true)
{
man1.jump =false;
uTime = 0;
man1.onKeyUp=man1KeyUp;
man1.onKeyDown=man1KeyDown;
}
}
function a()
{
this._y -= 2;
if (man1.hitTest(this))
{
man1._y = this._y - man1._height;
man1.onPlatform = true;
}
if ((((man1._x - this._x)/5 == 0) && man1.onPlatform == true))
{
man1._xlmax = true;
}
if ((man1._x+man1._width == this._x + 200+(man1._width/2)) && man1.onPlatform == true)
{
man1._xrmax = true;
}
trace(this._x);
if (this._y < 0)
{
this.removeMovieClip();
}
}
attachMovie(&quotlatform",&quotlatform0",1);
platform0._x = 300;
platform0._y = 200;
platform0.onEnterFrame = a;
attachMovie(&quotlatform",&quotlatform1",2);
platform1._x = 500;
platform1._y = 600;
platform1.onEnterFrame = a;
attachMovie(&quotlatform",&quotlatform2",3);
platform2._x = 100;
platform2._y = 1000;
platform2.onEnterFrame = a;
attachMovie("man","man1",1000);
man1._width = 30;
man1._height = 30;
man1._x = 320;
man1._y = 150;
man1.onEnterFrame = man;

This is my whole code.
Please let me know what is going wrong.
Thank you.
nananya
offline
nananya
3 posts
Nomad

It is solved by removing the _xlmax and _xrmax.
Thank you for reply.

Showing 1-2 of 3