Depends on the POV...


So we decided to increase the map size

From the start Catalization had a small, fixed size map but as we all know the factory must grow so does our game. It will be necessary for what is coming next but I don't want to spoil too much so stay tuned for the soon update. Increasing the map itself is easy enough since our one and only @InfinityZxc was smart and made it dynamically generated. The issue actually comes with the size: it won't fit on the screen. Making tiles smaller isn't really an option we don't want them tiny. So a moving map had to be made.

Smoke and mirrors

We wouldn't be game developers if we didn't attempt to deceive our players on the way. You see, moving all the game objects nicely laid down on the canvas would be hard and wasteful. Instead we can move the player's POV in the opposing direction and Defold has just the tool for it. A camera object is a special kind of game object which lets the developer control what the player sees and how. Let's dig into it but first huge props to @britzl and co for a very helpful library wrapper defold-orthographic.

Change your world views

If you're anything like me then playing video games you always wondered what is there behind the edge of the game world. Buckle up cause I'm taking you there right now.

There is nothing. Reality is often disappointing but our next update won't be ;)

Notice how all the GUI elements stayed in their place. Minimal setup was required to make it that way since orthographic takes care of it for us. Only background and clouds had to be attached to the camera object directly because these are not technically GUI elements due to some layering issues. So that's it? Unfortunately, no.

What you see isn't what you get

Once again consider our last screenshot. I grabbed the tile to place but it didn't move with the cursor. There is an offset instead which comes from 2 different (window and world) coordinate systems which we should consider while using a camera. With camera centered these are actually equivalent:

That's why we had no such problems earlier. But if I move the camera a little...

...they get out of sync! Window coordinate system as the name suggests has it's (0, 0) point locked to the lower left corner of the window while world coordinates are locked to be relative to our initial (0, 0) point no matter the camera movement. Defold reads input in window coordinate system but all the game objects have to use world coordinates if they don't want to be mashed together. All of this can cause some confusion but hopefully not for us. We just take a helper function window_to_world from britzl's lovely package and do a little refactoring. Voila! After just 2 changed lines of code new tile game object spawns with respect to the placement of the camera. Now we just have to repeat our refactoring steps for all clickable entities.

I believe some testing is due so I will no longer postpone it. Hopefully, your view of our game will only get better.

Stay safe!

Get Catalization

Leave a comment

Log in with itch.io to leave a comment.