Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Coding help?!?! Probably an easy fix!

Community Beginner ,
Jun 18, 2015 Jun 18, 2015

I need someone to help me with this code ASAP!

I have a sprite that moves left and right and I have barriers on the sides. My right barrier works perfectly! My left however is fault and freezes the entire presentation!!

This is my code for the RIGHT BARRIER, the one that WORKS:

var collision:Boolean = false

this.addEventListener( Event.ENTER_FRAME, BoundaryCollision)

function BoundaryCollision( e:Event ):void

{

    if(BoundaryRt.hitTestObject(ScubaDiverPlayer))

    {

           collision = true;

       }

  if(BoundaryRt.hitTestObject(ScubaDiverPlayer_left))

    {

           collision = true;

       } 

  if (collision)

    {

    while (collision)

  {

  ScubaDiverPlayer.x -= 0.00001;

  collision = false;

  if(BoundaryRt.hitTestObject(ScubaDiverPlayer))

    {

            collision = true;

      }

   }

}

}

My code for the left is basically the same, except that instead of the character facing right, it's facing left and instead of barrier and collision right, they're left.

This is the code for the LEFT BARRIER, the one that DOESN'T WORK:

var collisionLt:Boolean = false;

this.addEventListener( Event.ENTER_FRAME, LtBoundaryCollision)

function LtBoundaryCollision( e:Event ):void

{

  if(BoundaryLt.hitTestObject(ScubaDiverPlayer_left))

    {

    trace("two");

           collisionLt = true;

       }

 

  if (collisionLt)

    {

  trace("three");

    while (collisionLt)

  {

  ScubaDiverPlayer_left.x += 0.00001;

  collisionLt = false;

  trace("four");

  if(BoundaryLt.hitTestObject(ScubaDiverPlayer_left))

    {

  trace("five");

            collisionLt = true;

      }

  }

  }

}

I believe the problem is at the while(collisionLt), if I remove the ScubaDiverPlayer_left.x += 0.00001; line, I still get the trace in my output, however when I have that line, everything freezes when the placer collides with the boundary. Any suggestions as to why this may be occurring? Possibly layer order, code order, translation error?? I thought maybe it was the +=....


Please help!!

TOPICS
ActionScript
159
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2015 Jun 18, 2015
LATEST

sprite x and y properties are rounded to the nearest .05.

ie, use:

Monique Petrone wrote:

I need someone to help me with this code ASAP!

I have a sprite that moves left and right and I have barriers on the sides. My right barrier works perfectly! My left however is fault and freezes the entire presentation!!

This is my code for the RIGHT BARRIER, the one that WORKS:

var collision:Boolean = false

this.addEventListener( Event.ENTER_FRAME, BoundaryCollision)

function BoundaryCollision( e:Event ):void

{

    if(BoundaryRt.hitTestObject(ScubaDiverPlayer))

    {

           collision = true;

       }

  if(BoundaryRt.hitTestObject(ScubaDiverPlayer_left))

    {

           collision = true;

       }

  if (collision)

    {

    while (collision)

  {

  ScubaDiverPlayer.x -= 0.05;

  collision = false;

  if(BoundaryRt.hitTestObject(ScubaDiverPlayer))

    {

            collision = true;

      }

   }

}

}

My code for the left is basically the same, except that instead of the character facing right, it's facing left and instead of barrier and collision right, they're left.

This is the code for the LEFT BARRIER, the one that DOESN'T WORK:

var collisionLt:Boolean = false;

this.addEventListener( Event.ENTER_FRAME, LtBoundaryCollision)

function LtBoundaryCollision( e:Event ):void

{

  if(BoundaryLt.hitTestObject(ScubaDiverPlayer_left))

    {

    trace("two");

           collisionLt = true;

       }

  if (collisionLt)

    {

  trace("three");

    while (collisionLt)

  {

  ScubaDiverPlayer_left.x += 0.05;

  collisionLt = false;

  trace("four");

  if(BoundaryLt.hitTestObject(ScubaDiverPlayer_left))

    {

  trace("five");

            collisionLt = true;

      }

  }

  }

}

I believe the problem is at the while(collisionLt), if I remove the ScubaDiverPlayer_left.x += 0.00001; line, I still get the trace in my output, however when I have that line, everything freezes when the placer collides with the boundary. Any suggestions as to why this may be occurring? Possibly layer order, code order, translation error?? I thought maybe it was the +=....


Please help!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines