Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by lazer

I had this problem before and assumed it had something to do with how I was generating and moving a background map in the code. However, I've pretty much recoded the entire project and now the only background maps are those created in Weltmeister. The issue is:

I have a 1136 x 640 game window with a background map of the same size (consisting of 16px tiles). This background map is set to preRender and Repeat.

I have camera code that's set to follow the player, which always stays visually in the middle of the screen.

When the player moves right and/or down, the background map repeats fine. Everything looks exactly as it should.

When the player moves up and/or left, the background map does not repeat properly. The next piece of map seems to load way too late, resulting in distortion (the kind you get when you have no background map at all).

Turning off preRender seems to fix this, but increases my draw calls massively and causes a lot of lag.

What am I missing here? I'm clearly doing something wrong, I just can't figure out why the map refuses to repeat in those two directions but has no problem with the other two...

1 decade ago by dominic

.preRender can be a bit flaky with repeating backgrounds. Try making the map a bit bigger in WM (i.e. repeat it twice), or try to increase the .chunkSize to 1024.

Or limit your screen.x/y coordinates so that they never become negative – the problem only occurs with negative screen coordinates, right?

1 decade ago by lazer

Thanks, Dominic. Unfortunately making the map bigger and increasing chunkSize to 1024 didn't seem to have any effect.

With the latter solution - I'm not quite sure how I'd implement this. I need the player to be able to move indefinitely into any direction until they run out of fuel, so the distance is not limited by coordinates but by how much of a resource the player has. How would I limit screen.x/y without also limiting the player's ability to move in any direction?

1 decade ago by dominic

Oh, I'm sorry, I just assumed your game world is finite.

Can you please try the following: in the lib/impact/background-map.js, around line 135, replace the if( this.repeat ){ ... } block with the following:
if( this.repeat ) {
	var w = this.width * this.tilesize * ig.system.scale;
	dx = (dx%w + w) % w;

	var h = this.height * this.tilesize * ig.system.scale;
	dy = (dy%h + h) % h;
}

This ensures that dx and dy are always positive. I think it should fix your issue.

1 decade ago by SlouchCouch

I have an infinite scrolling game and much like Dominic's Drop example game when the position of screen.x or screen.y get to a certain value I shift the maps and also shift all entities at he same time. Then I reset screen.x or .y to some lower value. The results are all the entities and screen position values stay between two arbitrary values and there is the illusion of the player running infinitely in one direction.

Might be different from your game as my motion is al in one direction, and yours sounds like four directions with the ability to change direction.

-Dave aka @mrlasertron

1 decade ago by lazer

That worked perfectly, Dominic, thank you.

And thanks for your advice also, Dave.
Page 1 of 1
« first « previous next › last »