Defold Orthographic - The Orthographic Camera API

In your camera.script you do a string comparison with the message id:

if message_id == "changeZoom" then

Message ids are always hashed strings:

if message_id == hash("changeZoom") then

2 Likes

Thank you. :man_facepalming:

Hello,

I’ve tried to use your camera, but i’ve got a strange bug when the render script is launching.

Your sample is working, so it’s a problem with my project, but i don’t understand.

The problem is in the script camera.lua, required by the renderer script.

For narrowing the issue, i’ve made a debug project: britz_camera.zip (6.9 KB)

git clone defold-orthographic

copy orthographic directory to my new project.

creating game.project.

creating main.collection , input.input_binding.

adding to game project the collection, the input binding and the render found in /orthographic/render/orthographic.render

At this step, i already have the error:

ERROR:SCRIPT: orthographic.camera:15: attempt to perform arithmetic on local ‘DISPLAY_WIDTH’ (a nil value)

Same problem with DISPLAY_HEIGHT.

sys.get_config(…) returns nil !

local DISPLAY_WIDTH = tonumber(sys.get_config("display.width"))
local DISPLAY_HEIGHT = tonumber(sys.get_config("display.height"))

(the script is working if i assign numerical values to DISPLAY_WIDTH and DISPLAY_HEIGHT )

I don’t understand, because your sample is working.

Thank you for reading :slight_smile:

Oh, sorry, i’ve understood the problem!

If i leave the default values for display section in the game.project, then the querying of display.width and display.height will return nil.

If i change the default values (960x640) to something different (1024x768), then the sys.get_config will return the correct values.

So that’s only annoying if you want your game running in 960x640 resolution :slight_smile:

Thank you for reading :slight_smile:

1 Like

You can probably type 960x640 manually in game.project and get that to work.

1 Like

@britzl How to use this library when there are a few states (menu and game screens for example) ?
for example, how to implement this lib in this your example of MenuAndGame

I added camera.go to controller.collection

from game.script I call:

msg.post(“controller:/camera#script”, “follow”, { target = self.followMe })

and got the error:

/orthographic/camera.lua:203: Instance (null) not found

Thanks!

I would use multiple cameras and enable/disable them as I switch screens.

This seems to indicate that self.followMe is nil. Perhaps the object you’re supposed to follow has been deleted?

BTW I’ve released a new version (1.4.2) of the library that adds argument asserts on all public facing functions to warn when this happens.

2 Likes

no, when I add the camera to game.collection. there are no errors.
but okay, I can try to use each camera for each screen collections.

EDIT: yes. I like the solution with where each state has own camera. Thanks!

1 Like

@britzl any idea how to add the follow_point(x,y) function?

go.set_position(vmath.vector3(x,y,0), “camera id”) should be enough. The camera centers the view on its position.

1 Like

Thanks!

How should I proceed to add black bars to orthographic? Going for a specific look and don’t want to show more of the game screen than necessary when aspect ratio changes :slight_smile:

You can either tinker in render script to adjust your window size (e.g. Subtract some value out of height and add offset on the bottom or use fixed values as you probably want), see https://github.com/britzl/defold-orthographic, section manual integration and update function or… just add 2 simple box nodes in your gui that will cover those parts of the screen? :grin: Depending on what you need :wink:

2 Likes

I’ve released a new version of Orthographic. The new version supports a custom viewport per camera. This makes it very easy to setup and use multiple cameras, for instance when doing split-screen multiplayer. The new version introduced some breaking changes:

  • BREAKING CHANGE: Removed orthographic/render/helper.lua
  • BREAKING CHANGE: Removed Offset GUI option. Shake+recoil offset can still be retrieved using get_offset().
  • NEW: Camera viewport settings
  • NEW: Camera render order setting (lower value first)
  • NEW: Camera list using get_cameras()

Learn more: GitHub - britzl/defold-orthographic: Orthographic camera functionality for the Defold game engine

15 Likes

Noob question alert…

  1. Add camera.go to your game.

After adding dependency I can see camera.go in orthographic folder, but how add it to my game?
From tutorials I know that to add Game Object I have to use Factory. Do I need Factory in this case too?

For me as a guy who just passed all tutorial projects - add Game Object to your game is not clear instruction… Who can write step by step solution for me based on Walking astronaut tutorial project? Thanks!

P.S. I’ve added render as stated below, but I see black screen after building any of tutorial projects.

  1. Open game.project and make sure to reference orthographic/render/orthographic.render in the Render field in the Bootstrap section.
1 Like

check this example:

1 Like

Open a collection file and right click in the outline (top right editor panel) and select Add Gameobject File.

1 Like

@britzl @BunBunBun Thanks guys! Digging into it :slight_smile:

This is about the 3rd time I have edited this question as I slowly understand more:-)
I misunderstood how local variables in Lua modules work. I thought different ‘requires’ in different files would result in different instances of a local variable, of the required file, but it does not seem to be the case! Paradigm shift for me!
So my question reduces to:

Are there any tutorials on the use of the Orthographic camera?
I now am getting stuff to work but it would be good to see more examples of usage.

When running the master, if (All Features,Deadzone,bounds) is selected then after a few mouse clicks the player vanishes and does not return, why does this occur? Also on mouse click the camera shakes, as expected, and the player vanishes for about a second; why does the player vanish & is there a fix? The browser example linked on the github page is not the same as the git hub master version, it does not have these problems.

Thanks.

It could be that the z-position changes.

Please open tickets on GitHub for the things you’ve mentioned and I’ll take a look at them one by one!