Lag on certain tiles with Tilemaps

I’ve been having a rather elusive issue with certain tiles in a tilemap seeming to lag behind the rest for a little bit. It can be seen in this image:

(All of the bullets in the image are tiles.) As you can see, the large bullet third from the left (and the fourth from the left, as well, but to a lesser extent), has lagged a bit out of position: all those bullets should form a nice arc.

It seems to occur mostly on the last bullet in a series of bullet spawns, so I can sometimes fix it by creating an invisible bullet to eat the lag after all the others, but it doesn’t always work. Overall, it happens under seemingly random circumstances, though once the circumstance is found, it tends to be reproducable.

Has anyone run into this before?

You migth want to check your movement update and the math on your angle manipulation. It seems a little unlikely this has anything to do with Tile under the hood (but it may be possible). What version of openfl are you using?

I would assume that it’s my code, as well: I wanted to make sure this wasn’t a common thing with tilemaps or something to that effect. The angles are always correct, it’s just like it skips updating a bullets position for a few frames occasionally.

I’m pretty sure I’m using 8.9.5.

This should not be a problem with the tilemap, it may be a problem with the logic of the bullet? :wink:

That would make sense, I’m just not sure why.

I store each bullet’s velocity in a Vector2, and then run an update function every frame that loops over every bullet, and adds the Vector2’s individual values to both the bullet’s x and y position. I can’t see a point that would even allow that function to skip a bullet for a couple frames…

A common possibility is that when the bullets are removed, the array has undergone some microsecond changes, resulting in some bullets not being traversed.

Error:

for(var bullet in array){
    if(bullet.y > 500)
        array.remove(bullet);
    else
        bullet.move();
}

Solution(This will not affect bullet traversal):

var i = array.length;
while(i > 0){
    i --;
    var bullet = array[i];
    if(bullet.y > 500)
        array.remove(bullet);
    else
        bullet.move();
}
1 Like

So instead of looping over an array, use a while loop? I could give that a shot.

The only difference between them is that they changed from ascending order to descending order.

Don’t use:

var i = 0;
while(i < array.length){
    var bullet = array[i];
    if(bullet.y > 500)
        array.remove(bullet);
    else
        bullet.move();
     i ++;
}

That does seem to have removed the issue, in a quick test. I’ll only be really able to tell over a large period of time, but it works right now.

Thanks for the help!