在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:britzl/defold-orthographic开源软件地址:https://github.com/britzl/defold-orthographic开源编程语言:Lua 87.6%开源软件介绍:defold-orthographicOrthographic camera API for the Defold game engine. The API makes it super easy to convert screen to world coordinates, smoothly follow a game object and create a screen shake effect. This project is inspired by the camera component of the Phaser engine. The project is shipped with an example that shows all the features of the orthographic camera. Test the example app in your browser. InstallationYou can use the orthograpic camera in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add: https://github.com/britzl/defold-orthographic/archive/master.zip Or point to the ZIP file of a specific release. Quick StartGetting started with Orthographic is easy:
Next step is to read read the section on "Camera Configuration" to learn how to change the behavior of the camera. Camera ConfigurationSelect the script component attached to the near_z (number) and far_z (number)This is the near and far z-values used in the projection matrix, ie the near and far clipping plane. Anything with a z-value inside this range will be drawn by the render script. zoom (number)This is the zoom level of the camera. Modify it by calling Note that when using
order (number)The order in which multiple cameras should be drawn, lower is drawn first. projection (hash)The camera can be configured to support different kinds of orthographic projections. The default projection (aptly named
Note: For the above projections to work you need to pass the window dimensions from your render script to the camera. See the section on render script integration. Additional custom projections can be added, see enabled (boolean)This controls if the camera is enabled by default or not. Send follow (boolean)This controls if the camera should follow a target or not. See follow_horizontal (boolean)This controls if the camera should follow the target along the horizontal axis or not. See follow_vertical (boolean)This controls if the camera should follow the target along the vertical axis or not. See follow_immediately (boolean)This controls if the camera should immediately position itself on the follow target when initialized or if it should apply lerp (see below). See follow_target (hash)Id of the game object to follow. See follow_lerp (number)Amount of lerp when following a target. See follow_offset (vector3)Camera offset from the position of the followed target. See bounds_left (number), bounds_right (number), bounds_top (number), bounds_bottom (number)The camera bounds. See deadzone_left (number), deadzone_right (number), deadzone_top (number), deadzone_bottom (number)The camera deadzone. See viewport_left (number), viewport_right (number), viewport_top (number), viewport_bottom (number)The camera viewport. Render script integrationIn order for the Orthographic camera to function properly you need to integrate it in your render script. You can do this in a number of different ways: 1. Using the provided render scriptThe Orthographic API comes with a ready to use render script in 2. Integrating in an existing render scriptGet a list of active cameras and apply the camera viewport, view and projection before drawing:
Example render scriptThe Window vs Screen coordinatesThe camera API allows you to convert to and from world coordinates. This is useful when positioning a game object at the position of the mouse or knowing where in a game world a mouse click was made. The API supports conversion from both window and screen coordinates. Screen coordinatesThis refers to the actual mouse pixel position within the window, scaled to the display size specified in game.project. These are the values from Window coordinatesThis refers to the actual mouse pixel position within the window. These are the values from The Orthographic Camera API - functionsThe API can be used in two ways:
camera.get_view(camera_id)Get the current view of the camera. PARAMETERS
RETURN
camera.get_viewport(camera_id)Get the current viewport of the camera. PARAMETERS
RETURN
camera.get_projection(camera_id)Get the current projection of the camera. PARAMETERS
RETURN
camera.get_projection_id(camera_id)Get the current projection id of the camera. PARAMETERS
RETURN
camera.shake(camera_id, [intensity], [duration], [direction], [cb])Shake the camera. PARAMETERS
camera.stop_shaking(camera_id)Stop shaking the camera. PARAMETERS
camera.recoil(camera_id, offset, [duration])Apply a recoil effect to the camera. The recoil will decay using linear interpolation. PARAMETERS
camera.get_offset(camera_id)Get the current offset of the camera (caused by shake or recoil) PARAMETERS
RETURN
camera.get_zoom(camera_id)Get the current zoom level of the camera. PARAMETERS
RETURN
camera.set_zoom(camera_id, zoom)Change the zoom level of the camera. PARAMETERS
camera.follow(camera_id, target, [options])Follow a game object. PARAMETERS
Acceptable values for the
camera.follow_offset(camera_id, offset)Change the camera follow offset. PARAMETERS
camera.unfollow(camera_id)Stop following a game object. PARAMETERS
camera.deadzone(camera_id, left, top, right, bottom)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. PARAMETERS
camera.bounds(camera_id, left, top, right, bottom)Limits the camera position to within the specified rectangle. PARAMETERS
camera.screen_to_world(camera_id, screen)Translate screen coordinates to world coordinates, based on the view and projection of the camera. PARAMETERS
RETURN
camera.window_to_world(camera_id, window)Translate window coordinates to world coordinates, based on the view and projection of the camera. PARAMETERS
RETURN
camera.screen_to_world_bounds(camera_id)Translate screen boundaries (corners) to world coordinates, based on the view and projection of the camera. PARAMETERS
RETURN
camera.world_to_screen(camera_id, world, [adjust_mode])Translate world coordinates to 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. PARAMETER
RETURN
camera.unproject(view, projection, screen)Translate screen coordinates to world coordinates using the specified view and projection. PARAMETERS
RETURN
camera.project(view, projection, world)Translate world coordinates to screen coordinates using the specified view and projection. PARAMETERS
RETURN
camera.add_projector(projector_id, projector_fn)Add a custom projector that can be used by cameras in your project (see configuration above). PARAMETERS
camera.use_projector(camera_id, projector_id)Set a specific projector for a camera. This must be either one of the predefined projectors (see above) or a custom projector added using PARAMETERS
camera.set_window_scaling_factor(scaling_factor)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 to get the window scaling factor. PARAMETERS
camera.get_window_size()Get the current window size. The default values will be the ones specified in game.project. RETURN
camera.get_display_size()Get the display size, as specified in game.project. RETURN
The Orthographic Camera API - messagesMost of the functions of the API have message equivalents that can be sent to the camera component. shakeMessage equivalent to
stop_shakingMessage equivalent to
recoilMessage equivalent to
shake_completeMessage sent back to the sender of a followMessage equivalent to
follow_offsetMessage equivalent to
unfollowMessage equivalent to
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论