Skip to content

Commit 23f6b16

Browse files
committed
Use first camera if none is provided
1 parent f7d9335 commit 23f6b16

File tree

2 files changed

+120
-50
lines changed

2 files changed

+120
-50
lines changed

README.md

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Or point to the ZIP file of a [specific release](https://github.com/britzl/defol
1414
Getting started with Orthographic is easy:
1515

1616
1. Add `camera.go` to your game.
17-
2. Open `game.project` and make sure to reference `orthographic/render/orthograpic.render` in the `Render` field in the `Bootstrap` section.
17+
2. Open `game.project` and make sure to reference `orthographic/render/orthograpic.render` in the `Render` field in the `Bootstrap` section.
1818

1919
Next step is to read read the section on "Camera Configuration" to learn how to change the behavior of the camera.
2020

@@ -130,6 +130,48 @@ The API can be used in two ways:
130130
2. Sending messages to the `camera.script`
131131

132132

133+
134+
### camera.get_view(camera_id)
135+
Get the current view of the camera.
136+
137+
**PARAMETERS**
138+
* `camera_id` (hash|url|nil) nil for the first camera
139+
140+
**RETURN**
141+
* `view` (matrix) The current view
142+
143+
### camera.get_viewport(camera_id)
144+
Get the current viewport of the camera.
145+
146+
**PARAMETERS**
147+
* `camera_id` (hash|url|nil) nil for the first camera
148+
149+
**RETURN**
150+
* `x` (number) The viewport left position
151+
* `y` (number) The viewport bottom position
152+
* `w` (number) The viewport width
153+
* `h` (number) The viewport height
154+
155+
### camera.get_projection(camera_id)
156+
Get the current projection of the camera.
157+
158+
**PARAMETERS**
159+
* `camera_id` (hash|url|nil) nil for the first camera
160+
161+
**RETURN**
162+
* `projection` (matrix) The current projection
163+
164+
### camera.get_projection_D(camera_id)
165+
Get the current projection id of the camera.
166+
167+
**PARAMETERS**
168+
* `camera_id` (hash|url|nil) nil for the first camera
169+
170+
**RETURN**
171+
* `projection_id` (hash) The current projection id
172+
173+
---
174+
133175
### camera.shake(camera_id, [intensity], [duration], [direction], [cb])
134176
Shake the camera.
135177

@@ -140,7 +182,6 @@ Shake the camera.
140182
* `direction` (hash) - Direction of the shake. Possible values: `both`, `horizontal`, `vertical`. Defaults to `both`.
141183
* `cb` (function) - Function to call when the shake has finished. Optional.
142184

143-
144185
### camera.stop_shaking(camera_id)
145186
Stop shaking the camera.
146187

@@ -155,12 +196,22 @@ Apply a recoil effect to the camera. The recoil will decay using linear interpol
155196
* `offset` (vector3) - Offset to apply to the camera. Defaults to 0.05
156197
* `duration` (number) - Duration of the recoil, in seconds. Defaults to 0.5
157198

199+
### camera.get_offset(camera_id)
200+
Get the current offset of the camera (caused by shake or recoil)
201+
202+
**PARAMETERS**
203+
* `camera_id` (hash|url|nil) nil for the first camera
204+
205+
**RETURN**
206+
* `offset` (vector3) The current offset of the camera
207+
208+
---
158209

159210
### camera.get_zoom(camera_id)
160211
Get the current zoom level of the camera.
161212

162213
**PARAMETERS**
163-
* `camera_id` (hash|url)
214+
* `camera_id` (hash|url|nil) nil for the first camera
164215

165216
**RETURN**
166217
* `zoom` (number) The current zoom of the camera
@@ -170,15 +221,16 @@ Get the current zoom level of the camera.
170221
Change the zoom level of the camera.
171222

172223
**PARAMETERS**
173-
* `camera_id` (hash|url)
224+
* `camera_id` (hash|url|nil) nil for the first camera
174225
* `zoom` (number) The new zoom level of the camera
175226

227+
---
176228

177229
### camera.follow(camera_id, target, [options])
178230
Follow a game object.
179231

180232
**PARAMETERS**
181-
* `camera_id` (hash|url)
233+
* `camera_id` (hash|url|nil) nil for the first camera
182234
* `target` (hash|url) - Game object to follow
183235
* `options` (table) - Options (see below)
184236

@@ -195,22 +247,23 @@ Acceptable values for the `options` table:
195247
Change the camera follow offset.
196248

197249
**PARAMETERS**
198-
* `camera_id` (hash|url)
250+
* `camera_id` (hash|url|nil) nil for the first camera
199251
* `offset` (vector3) - Camera offset from target position.
200252

201253

202254
### camera.unfollow(camera_id)
203255
Stop following a game object.
204256

205257
**PARAMETERS**
206-
* `camera_id` (hash|url)
258+
* `camera_id` (hash|url|nil) nil for the first camera
207259

260+
---
208261

209262
### camera.deadzone(camera_id, left, top, right, bottom)
210263
If following a game object this will add a deadzone around the camera position where the camera position will not update. If the target moves to the edge of the deadzone the camera will start to follow until the target returns within the bounds of the deadzone.
211264

212265
**PARAMETERS**
213-
* `camera_id` (hash|url)
266+
* `camera_id` (hash|url|nil) nil for the first camera
214267
* `left` (number) - Number of pixels to the left of the camera
215268
* `top` (number) - Number of pixels above the camera
216269
* `right` (number) - Number of pixels to the right of the camera
@@ -221,18 +274,19 @@ If following a game object this will add a deadzone around the camera position w
221274
Limits the camera position to within the specified rectangle.
222275

223276
**PARAMETERS**
224-
* `camera_id` (hash|url)
277+
* `camera_id` (hash|url|nil) nil for the first camera
225278
* `left` (number) - Left edge of the camera bounds
226279
* `top` (number) - Top edge of camera bounds
227280
* `right` (number) - Right edge of camera bounds
228281
* `bottom` (number) - Bottom edge of camera bounds
229282

283+
---
230284

231285
### camera.screen_to_world(camera_id, screen)
232286
Translate [screen coordinates](#screen-coordinates) to world coordinates, based on the view and projection of the camera.
233287

234288
**PARAMETERS**
235-
* `camera_id` (hash|url)
289+
* `camera_id` (hash|url|nil) nil for the first camera
236290
* `screen` (vector3) Screen coordinates to convert
237291

238292
**RETURN**
@@ -243,7 +297,7 @@ Translate [screen coordinates](#screen-coordinates) to world coordinates, based
243297
Translate [window coordinates](#window-coordinates) to world coordinates, based on the view and projection of the camera.
244298

245299
**PARAMETERS**
246-
* `camera_id` (hash|url)
300+
* `camera_id` (hash|url|nil) nil for the first camera
247301
* `window` (vector3) Window coordinates to convert
248302

249303
**RETURN**
@@ -254,7 +308,7 @@ Translate [window coordinates](#window-coordinates) to world coordinates, based
254308
Translate [screen boundaries](#screen-coordinates) (corners) to world coordinates, based on the view and projection of the camera.
255309

256310
**PARAMETERS**
257-
* `camera_id` (hash|url)
311+
* `camera_id` (hash|url|nil) nil for the first camera
258312

259313
**RETURN**
260314
* `bounds` (vector4) Screen bounds (x = left, y = top, z = right, w = bottom)
@@ -264,7 +318,7 @@ Translate [screen boundaries](#screen-coordinates) (corners) to world coordinate
264318
Translate world coordinates to [screen coordinates](#screen-coordinates), based on the view and projection of the camera, optionally taking into account an adjust mode. This is useful when manually culling game objects and you need to determine if a world coordinate will be visible or not. It can also be used to position gui nodes on top of game objects.
265319

266320
**PARAMETER**
267-
* `camera_id` (hash|url)
321+
* `camera_id` (hash|url|nil) nil for the first camera
268322
* `world` (vector3) World coordinates to convert
269323
* `adjust_mode` (number) One of gui.ADJUST_FIT, gui.ADJUST_ZOOM and gui.ADJUST_STRETCH, or nil to not take into account the adjust mode.
270324

@@ -295,6 +349,7 @@ Translate world coordinates to [screen coordinates](#screen-coordinates) using t
295349
**RETURN**
296350
* `screen_coords` (vector3) Note: Same v3 object as passed in as argument
297351

352+
---
298353

299354
### camera.add_projector(projector_id, projector_fn)
300355
Add a custom projector that can be used by cameras in your project (see configuration above).
@@ -308,17 +363,10 @@ Add a custom projector that can be used by cameras in your project (see configur
308363
Set a specific projector for a camera. This must be either one of the predefined projectors (see above) or a custom projector added using `camera.add_projector()`.
309364

310365
**PARAMETERS**
311-
* `camera_id` (hash) - Id of the camera to set projector for.
366+
* `camera_id` (hash|url|nil) nil for the first camera
312367
* `projector_id` (hash) - Id of the projector.
313368

314-
315-
### camera.set_window_size(width, height)
316-
Set the current window size so that it is available to projectors via `camera.get_window_size()`. Set this via your render script.
317-
318-
**PARAMETERS**
319-
* `width` (number) - Current window width.
320-
* `height` (number) - Current window height.
321-
369+
---
322370

323371
### camera.set_window_scaling_factor(scaling_factor)
324372
Set window scaling factor (basically retina or no retina screen). There is no built-in way to detect if Defold is running on a retina or non retina screen. This information combined with the High DPI setting in game.project can be used to ensure that the zoom behaves the same way regardless of screen type and High DPI setting. You can use an extension such as [DefOS](https://github.com/subsoap/defos) to get the window scaling factor.
@@ -328,7 +376,7 @@ Set window scaling factor (basically retina or no retina screen). There is no bu
328376

329377

330378
### camera.get_window_size()
331-
Get the current window size, as it was provided by `camera.set_window_size()`. The default values will be the ones specified in game.project.
379+
Get the current window size. The default values will be the ones specified in game.project.
332380

333381
**RETURN**
334382
* `width` (number) - Current window width.
@@ -342,6 +390,8 @@ Get the display size, as specified in game.project.
342390
* `width` (number) - Display width.
343391
* `height` (number) - Display height.
344392

393+
---
394+
345395
## The Orthographic Camera API - messages
346396
Most of the functions of the API have message equivalents that can be sent to the camera component.
347397

0 commit comments

Comments
 (0)