Defold Orthographic - The Orthographic Camera API

@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!

I’m trying to get your orthographic camera working, but appear not to be getting it right. I’ve added and fetched the library and have camera.go. in my game. But then can’t get the camera to follow the player.

Here’s some screenshots of what I’ve got setup so far - → Camera Lua - Google Slides

Thanks for any help!

John

Did you add camera.go to your scene?
Did you change the render script?

  1. Add camera.go to your game.
  2. Open game.project and make sure to reference orthographic/render/orthographic.render in the Render field in the Bootstrap section.

I’ve done the 2nd - Render Field.

Camera.go is added in the orthgraphic library. How do I add it to the game? Drag it into the ‘Main’ folder?

Open your Collection and (right click on Collection name) add a ‘Game Object File’, find camera.go and add it.

Click on camera script file, enable follow and add a target ID

3 Likes