Weird delay coming from class code.
Hey there,
I'm working on a game where sets of platforms come onto the screen one after another creating and infinite runner. I'm currently doing this, maybe not the most effective way but it hasn't cause any greif until now, by having two trigger MovieClips far off stage to the left. When hit by a platform, the first one is supposed to move the next platform into line and move it left. The second, placed just beyond the first, then sends the set of platforms off into the distance.
The issue that I'm running in to is, the second set of platforms spawns in where it should be, but then takes a second to move which makes the game completely impossible as the first platform slides out from under you.
Below is my code for these two triggers. Thank you in advance.
This is the code for the class that spawns the next set of platforms.
package {
import flash.display.*;
import flash.events.*;
public class PlatformReset extends MovieClip{
public var prevX:Number;
public var prevY:Number;
//construct function
public function PlatformReset():void
{
addEventListener(Event.ENTER_FRAME, collision);
}
private function collision(e:Event):void{
if(this.hitTestObject(MovieClip(root).Platform1)){
MovieClip(root).Platform2.x = 3200;
MovieClip(root).Platform2.y = 300;
MovieClip(root).Platform2.x -= MovieClip(root).worldSpeed;
trace("Platform2 Spawn");
}
else {
prevX = MovieClip(root).Platform2.x;
prevY = MovieClip(root).Platform2.y;
}
if(this.hitTestObject(MovieClip(root).Platform2)){
MovieClip(root).Platform1.x = 3200;
MovieClip(root).Platform1.y = 300;
MovieClip(root).Platform1.x -= MovieClip(root).worldSpeed;
trace("Platform1 Spawn");
}
else {
prevX = MovieClip(root).Platform1.x;
prevY = MovieClip(root).Platform1.y;
}
}
}
}
This is the class that then moves the first.
package {
import flash.display.*;
import flash.events.*;
public class Platform2ndTrigger extends MovieClip{
public var prevX:Number;
public var prevY:Number;
//construct function
public function Platform2ndTrigger():void
{
addEventListener(Event.ENTER_FRAME, collision);
}
private function collision(e:Event):void{
if(this.hitTestObject(MovieClip(root).Platform1)){
MovieClip(root).Platform1.x = 0;
MovieClip(root).Platform1.y = 1200;
//MovieClip(root).Platform1.stop();
MovieClip(root).Platform2.x -= MovieClip(root).worldSpeed;
trace("Platform1 Hit 2nd Trigger and Moved");
}
else {
//prevX = MovieClip(root).Platform1.x;
//prevY = MovieClip(root).Platform1.y;
}
if(this.hitTestObject(MovieClip(root).Platform2)){
MovieClip(root).Platform2.x = 0;
MovieClip(root).Platform2.y = 1200;
//MovieClip(root).Platform2.stop();
MovieClip(root).Platform1.x -= MovieClip(root).worldSpeed;
trace("Platform2 Hit 2nd Trigger and Moved");
}
else {
//prevX = MovieClip(root).Platform2.x;
//prevY = MovieClip(root).Platform2.y;
}
}
}
}