├── Icon camera.png ├── LICENSE.md ├── README.md └── addons └── carmel4a97.RTS_Camera2D ├── LICENSE ├── Plugin.gd ├── RTS-Camera2D.gd ├── node_icon.png └── plugin.cfg /Icon camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carmel4a/RTS-Camera2D/034b173855408a6b7e198a1a14ed172a3bea9e18/Icon camera.png -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # License 2 | 3 | Copyright 2017 Kamil Lewan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RTS Camera2d :movie_camera: 2 | 3 | RTS Camera2d plugin adds simple camera node to Godot Engine. You can control 4 | camera using arrow keys, by dragging while holding mouse button or by moving 5 | mouse cursor near to the screen edge. Despite the name, this node can be useful 6 | in any game genre, not only RTS :wink: 7 | 8 | # Installation 9 | 10 | Use AssetLib or download archive from [Github releases][releases] and extract `addons` directory to 11 | your project directory. Activate plugin in *Scene > Project Settings > Plugins* 12 | 13 | [releases]: https://github.com/carmel4a/RTS-Camera2D/releases "releases" 14 | 15 | # Usage 16 | 17 | Create *RTS-Camera2D* node on your scene. Make sure to check the `Current` property on 18 | in inspector. You can adjust behavior of the node using following properties 19 | 20 | | Property | Usage | 21 | | ---- | ---- | 22 | | Key | Move camera using keys binded to ui_* actions) like | 23 | | Drag | Move camera using mouse (right mouse button by default) | 24 | | Edge | Move camera when cursor is close to edge screen | 25 | | Wheel | Zoom in/out using scroll wheel | 26 | | Zoom Out Limit | How far you can zoom out | 27 | | Camera speed | self-explanatory | 28 | | Camera margin | how near to the window edge (in px) the mouse must be to move a view. | 29 | 30 | # Compatibly 31 | 32 | This plugin was tested in Godot Engine v2.1.3 (2.x banch) and v3.0 beta 1 (3.x branch). 33 | -------------------------------------------------------------------------------- /addons/carmel4a97.RTS_Camera2D/LICENSE: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Kamil Lewan 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | -------------------------------------------------------------------------------- /addons/carmel4a97.RTS_Camera2D/Plugin.gd: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Kamil Lewan 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | 21 | tool 22 | 23 | extends EditorPlugin 24 | 25 | func _enter_tree(): 26 | add_custom_type("RTS-Camera2D", "Camera2D", preload("RTS-Camera2D.gd"), preload("node_icon.png")) 27 | 28 | func _exit_tree(): 29 | remove_custom_type("RTS-Camera2D") 30 | -------------------------------------------------------------------------------- /addons/carmel4a97.RTS_Camera2D/RTS-Camera2D.gd: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Kamil Lewan 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | # SOFTWARE. 20 | 21 | extends Camera2D 22 | 23 | # Camera control settings: 24 | # key - by keyboard 25 | # drag - by clicking mouse button, right mouse button by default; 26 | # edge - by moving mouse to the window edge 27 | # wheel - zoom in/out by mouse wheel 28 | export (bool) var key = true 29 | export (bool) var drag = true 30 | export (bool) var edge = false 31 | export (bool) var wheel = true 32 | 33 | export (int) var zoom_out_limit = 100 34 | 35 | # Camera speed in px/s. 36 | export (int) var camera_speed = 450 37 | 38 | # Initial zoom value taken from Editor. 39 | var camera_zoom = get_zoom() 40 | 41 | # Value meaning how near to the window edge (in px) the mouse must be, 42 | # to move a view. 43 | export (int) var camera_margin = 50 44 | 45 | # It changes a camera zoom value in units... (?, but it works... it probably 46 | # multiplies camera size by 1+camera_zoom_speed) 47 | const camera_zoom_speed = Vector2(0.5, 0.5) 48 | 49 | # Vector of camera's movement / second. 50 | var camera_movement = Vector2() 51 | 52 | # Previous mouse position used to count delta of the mouse movement. 53 | var _prev_mouse_pos = null 54 | 55 | # INPUTS 56 | 57 | # Right mouse button was or is pressed. 58 | var __rmbk = false 59 | # Move camera by keys: left, top, right, bottom. 60 | var __keys = [false, false, false, false] 61 | 62 | func _ready(): 63 | set_h_drag_enabled(false) 64 | set_v_drag_enabled(false) 65 | set_enable_follow_smoothing(true) 66 | set_follow_smoothing(4) 67 | 68 | func _physics_process(delta): 69 | 70 | # Move camera by keys defined in InputMap (ui_left/top/right/bottom). 71 | if key: 72 | if __keys[0]: 73 | camera_movement.x -= camera_speed * delta 74 | if __keys[1]: 75 | camera_movement.y -= camera_speed * delta 76 | if __keys[2]: 77 | camera_movement.x += camera_speed * delta 78 | if __keys[3]: 79 | camera_movement.y += camera_speed * delta 80 | 81 | # Move camera by mouse, when it's on the margin (defined by camera_margin). 82 | if edge: 83 | var rec = get_viewport().get_visible_rect() 84 | var v = get_local_mouse_position() + rec.size/2 85 | if rec.size.x - v.x <= camera_margin: 86 | camera_movement.x += camera_speed * delta 87 | if v.x <= camera_margin: 88 | camera_movement.x -= camera_speed * delta 89 | if rec.size.y - v.y <= camera_margin: 90 | camera_movement.y += camera_speed * delta 91 | if v.y <= camera_margin: 92 | camera_movement.y -= camera_speed * delta 93 | 94 | # When RMB is pressed, move camera by difference of mouse position 95 | if drag and __rmbk: 96 | camera_movement = _prev_mouse_pos - get_local_mouse_position() 97 | 98 | # Update position of the camera. 99 | position += camera_movement * get_zoom() 100 | 101 | # Set camera movement to zero, update old mouse position. 102 | camera_movement = Vector2(0,0) 103 | _prev_mouse_pos = get_local_mouse_position() 104 | 105 | func _unhandled_input( event ): 106 | if event is InputEventMouseButton: 107 | if drag and\ 108 | event.button_index == BUTTON_RIGHT: 109 | # Control by right mouse button. 110 | if event.pressed: __rmbk = true 111 | else: __rmbk = false 112 | # Check if mouse wheel was used. Not handled by ImputMap! 113 | if wheel: 114 | # Checking if future zoom won't be under 0. 115 | # In that cause engine will flip screen. 116 | if event.button_index == BUTTON_WHEEL_UP and\ 117 | camera_zoom.x - camera_zoom_speed.x > 0 and\ 118 | camera_zoom.y - camera_zoom_speed.y > 0: 119 | camera_zoom -= camera_zoom_speed 120 | set_zoom(camera_zoom) 121 | # Checking if future zoom won't be above zoom_out_limit. 122 | if event.button_index == BUTTON_WHEEL_DOWN and\ 123 | camera_zoom.x + camera_zoom_speed.x < zoom_out_limit and\ 124 | camera_zoom.y + camera_zoom_speed.y < zoom_out_limit: 125 | camera_zoom += camera_zoom_speed 126 | set_zoom(camera_zoom) 127 | # Control by keyboard handled by InpuMap. 128 | if event.is_action_pressed("ui_left"): 129 | __keys[0] = true 130 | if event.is_action_pressed("ui_up"): 131 | __keys[1] = true 132 | if event.is_action_pressed("ui_right"): 133 | __keys[2] = true 134 | if event.is_action_pressed("ui_down"): 135 | __keys[3] = true 136 | if event.is_action_released("ui_left"): 137 | __keys[0] = false 138 | if event.is_action_released("ui_up"): 139 | __keys[1] = false 140 | if event.is_action_released("ui_right"): 141 | __keys[2] = false 142 | if event.is_action_released("ui_down"): 143 | __keys[3] = false 144 | -------------------------------------------------------------------------------- /addons/carmel4a97.RTS_Camera2D/node_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carmel4a/RTS-Camera2D/034b173855408a6b7e198a1a14ed172a3bea9e18/addons/carmel4a97.RTS_Camera2D/node_icon.png -------------------------------------------------------------------------------- /addons/carmel4a97.RTS_Camera2D/plugin.cfg: -------------------------------------------------------------------------------- 1 | [plugin] 2 | 3 | name="RTS-Camera2D" 4 | description="A Camera2D with basic movement behavior." 5 | author="Kamil Lewan " 6 | version="1.0" 7 | script="Plugin.gd" 8 | 9 | # Copyright 2017 Kamil Lewan 10 | # 11 | # Permission is hereby granted, free of charge, to any person obtaining a copy 12 | # of this software and associated documentation files (the "Software"), to deal 13 | # in the Software without restriction, including without limitation the rights 14 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | # copies of the Software, and to permit persons to whom the Software is 16 | # furnished to do so, subject to the following conditions: 17 | # 18 | # The above copyright notice and this permission notice shall be included in all 19 | # copies or substantial portions of the Software. 20 | # 21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | # SOFTWARE. 28 | --------------------------------------------------------------------------------