Map larger than game dimensions


(Ricesteam) #1

I have a map that’s larger than the game dimension and the screen goes black after camera goes over.

E.g. My game dimension is 640x480 and my map is 1600x480. Once camera.x > 640, the screen is black.

Is there a work around to this problem or am I stuck with a upper limit of map size for my game dimensions?


(Jacob Albano) #2

How exactly are you moving the camera? That shouldn’t be happening.


(Ricesteam) #3

On every update I set the camera.x to the player’s x. Eg

FP.camera.x = player.x - FP.halfWidth;

(Jacob Albano) #4

This is probably a stupid question, but there are things to see past x = 640, right?


(Ricesteam) #5

It’s a valid question: yes there are things to see past x = 640. The screen suddenly goes black. Looking at the debug console, as soon as camera.x > 640, the screen goes black.


(Zachary Lewis) #6

You might want to look at the sample game created with FlashPunk. It has a map larger than the screen that the player can explore.


(Jacob Albano) #7

The only thing I can think of is that you might be doing some calculation that causes FP.camera.x to be NaN at some point. I’ve never had that problem before.

Do you have some code you can show us? Anywhere that you set the camera’s position or the player’s position.


(Ricesteam) #8

I have a camera class with simple followPlayer public function.

public function followPlayer(player:Player):void {
    FP.camera.x = player.x - FP.halfwidth;
}

It is called on my level updates().

The game doesn’t freeze, it just draws a black screen over everyhing. I can see hitboxes in the FP.console. The max map size I can have is the game width * 2. Eg. 640 * 2 = 1280 is the upper limit.


(Zachary Lewis) #9

Do you have your source code anywhere? I’d take a look at it for you. You can use Gist to put your source up.


(Ricesteam) #10

I took the camera code from Pink and still the same bug. I wonder if the flash player version has anything to do with this problem.

Here’s the camera code: https://gist.github.com/peterhoang/6008605

My main starts the engine with super(640, 480, 60).

I should add that the game is not frozen. The camera still tracks the player and I can interact with the player. The screen just renders black after a certain point. All except the FP.console is visible. In my case, after camera.x > 640. I haven’t tested the y-coordinates.


(Zachary Lewis) #11

I think I’ve spotted your problem.

You were using FP.point (which is not a great idea, since it gets used by FP in many calculations and probably needs to be optimized).

Here’s my suggested change.


(Jacob Albano) #12

Ah, that will definitely do it. FP.point is used in order to avoid constructing new Point instances every frame for performance reasons. It shouldn’t be used in your own code.


(Ricesteam) #13

Thanks guys for looking into this.

Unfortunately, the change didn’t fix the problem.

It must be something else then. Perhaps, the way I load the tiles from a map? I will look into this further after work.


(Ricesteam) #14

Ok I was stupid. I used ShillySit’s Lit engine and didn’t initialize it to the right dimensions! After passing in my map size, the game works as intended!

Sorry guys, made you go on a wild goose chase…


(Zachary Lewis) #15


(Ultima2876) #16

Ahaha, happens to the best of us!