Copy link to clipboard
Copied
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!!
Copy link to clipboard
Copied
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!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now