Skip to content

Commit fd968ab

Browse files
committed
Added stop_shaking
1 parent 9837b15 commit fd968ab

File tree

5 files changed

+182
-0
lines changed

5 files changed

+182
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ Shake the camera.
107107
* ```direction``` (hash) - Direction of the shake. Possible values: ```both```, ```horizontal```, ```vertical```. Defaults to ```both```.
108108
* ```cb``` (function) - Function to call when the shake has finished. Optional.
109109

110+
### camera.stop_shaing(camera_id)
111+
Stop shaking the camera.
112+
113+
**PARAMETERS**
114+
* ```camera_id``` (hash|url)
115+
110116
### camera.follow(camera_id, target, [lerp])
111117
Follow a game object.
112118

@@ -241,6 +247,9 @@ Get the display size, as specified in game.project.
241247
### shake
242248
Message equivalent to ```camera.shake()```. Supports ```intensity```, ```duration``` and ```direction```.
243249

250+
### stop_shaking
251+
Message equivalent to ```camera.stop_shaking()```.
252+
244253
### shake_complete
245254
Message sent back to the sender of a ```shake``` message when the shake has completed.
246255

example/camera_controls.gui

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,165 @@ nodes {
17201720
text_leading: 1.0
17211721
text_tracking: 0.0
17221722
}
1723+
nodes {
1724+
position {
1725+
x: 513.154
1726+
y: 84.266
1727+
z: 0.0
1728+
w: 1.0
1729+
}
1730+
rotation {
1731+
x: 0.0
1732+
y: 0.0
1733+
z: 0.0
1734+
w: 1.0
1735+
}
1736+
scale {
1737+
x: 1.0
1738+
y: 1.0
1739+
z: 1.0
1740+
w: 1.0
1741+
}
1742+
size {
1743+
x: 200.0
1744+
y: 100.0
1745+
z: 0.0
1746+
w: 1.0
1747+
}
1748+
color {
1749+
x: 1.0
1750+
y: 1.0
1751+
z: 1.0
1752+
w: 1.0
1753+
}
1754+
type: TYPE_TEMPLATE
1755+
id: "stop_shaking"
1756+
parent: "buttons"
1757+
layer: ""
1758+
inherit_alpha: true
1759+
alpha: 1.0
1760+
template: "/example/assets/button.gui"
1761+
template_node_child: false
1762+
}
1763+
nodes {
1764+
position {
1765+
x: 0.0
1766+
y: 0.0
1767+
z: 0.0
1768+
w: 1.0
1769+
}
1770+
rotation {
1771+
x: 0.0
1772+
y: 0.0
1773+
z: 0.0
1774+
w: 1.0
1775+
}
1776+
scale {
1777+
x: 1.0
1778+
y: 1.0
1779+
z: 1.0
1780+
w: 1.0
1781+
}
1782+
size {
1783+
x: 100.0
1784+
y: 40.0
1785+
z: 0.0
1786+
w: 1.0
1787+
}
1788+
color {
1789+
x: 1.0
1790+
y: 1.0
1791+
z: 1.0
1792+
w: 1.0
1793+
}
1794+
type: TYPE_BOX
1795+
blend_mode: BLEND_MODE_ALPHA
1796+
texture: "main/space"
1797+
id: "stop_shaking/button"
1798+
xanchor: XANCHOR_NONE
1799+
yanchor: YANCHOR_NONE
1800+
pivot: PIVOT_CENTER
1801+
adjust_mode: ADJUST_MODE_FIT
1802+
parent: "stop_shaking"
1803+
layer: "below"
1804+
inherit_alpha: true
1805+
slice9 {
1806+
x: 4.0
1807+
y: 4.0
1808+
z: 4.0
1809+
w: 4.0
1810+
}
1811+
clipping_mode: CLIPPING_MODE_NONE
1812+
clipping_visible: true
1813+
clipping_inverted: false
1814+
alpha: 1.0
1815+
template_node_child: true
1816+
size_mode: SIZE_MODE_MANUAL
1817+
}
1818+
nodes {
1819+
position {
1820+
x: 0.0
1821+
y: 0.0
1822+
z: 0.0
1823+
w: 1.0
1824+
}
1825+
rotation {
1826+
x: 0.0
1827+
y: 0.0
1828+
z: 0.0
1829+
w: 1.0
1830+
}
1831+
scale {
1832+
x: 1.0
1833+
y: 1.0
1834+
z: 1.0
1835+
w: 1.0
1836+
}
1837+
size {
1838+
x: 90.0
1839+
y: 100.0
1840+
z: 0.0
1841+
w: 1.0
1842+
}
1843+
color {
1844+
x: 1.0
1845+
y: 1.0
1846+
z: 1.0
1847+
w: 1.0
1848+
}
1849+
type: TYPE_TEXT
1850+
blend_mode: BLEND_MODE_ALPHA
1851+
text: "STOP SHAKING"
1852+
font: "silkscreen"
1853+
id: "stop_shaking/text"
1854+
xanchor: XANCHOR_NONE
1855+
yanchor: YANCHOR_NONE
1856+
pivot: PIVOT_CENTER
1857+
outline {
1858+
x: 1.0
1859+
y: 1.0
1860+
z: 1.0
1861+
w: 1.0
1862+
}
1863+
shadow {
1864+
x: 1.0
1865+
y: 1.0
1866+
z: 1.0
1867+
w: 1.0
1868+
}
1869+
adjust_mode: ADJUST_MODE_FIT
1870+
line_break: true
1871+
parent: "stop_shaking/button"
1872+
layer: "text"
1873+
inherit_alpha: true
1874+
alpha: 1.0
1875+
outline_alpha: 1.0
1876+
shadow_alpha: 1.0
1877+
overridden_fields: 8
1878+
template_node_child: true
1879+
text_leading: 1.0
1880+
text_tracking: 0.0
1881+
}
17231882
nodes {
17241883
position {
17251884
x: 640.0

example/camera_controls.gui_script

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ function on_input(self, action_id, action)
4545
msg.post("camera", "shake", { intensity = 0.05, duration = 0.5, direction = hash("horizontal") })
4646
elseif gui.pick_node(gui.get_node("shake_vertical/button"), action.x, action.y) then
4747
msg.post("camera", "shake", { intensity = 0.05, duration = 0.5, direction = hash("vertical") })
48+
elseif gui.pick_node(gui.get_node("stop_shaking/button"), action.x, action.y) then
49+
msg.post("camera", "stop_shaking")
4850
elseif gui.pick_node(gui.get_node("bounds/button"), action.x, action.y) then
4951
self.bounds_enabled = not self.bounds_enabled
5052
if self.bounds_enabled then

orthographic/camera.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,15 @@ function M.shake(camera_id, intensity, duration, direction, cb)
353353
end
354354

355355

356+
357+
--- Stop shaking a camera
358+
-- @param camera_id
359+
function M.stop_shaking(camera_id)
360+
assert(camera_id, "You must provide a camera id")
361+
cameras[camera_id].shake = nil
362+
end
363+
364+
356365
--- Get the projection matrix for a camera
357366
-- @param camera_id
358367
-- @return Projection matrix

orthographic/camera.script

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local DISABLE = hash("disable")
1111
local UNFOLLOW = hash("unfollow")
1212
local FOLLOW = hash("follow")
1313
local SHAKE = hash("shake")
14+
local STOP_SHAKING = hash("stop_shaking")
1415
local DEADZONE = hash("deadzone")
1516
local BOUNDS = hash("bounds")
1617
local UPDATE_CAMERA = hash("update_camera")
@@ -60,5 +61,7 @@ function on_message(self, message_id, message, sender)
6061
camera.shake(go.get_id(), message.intensity, message.duration, message.direction, function()
6162
msg.post(sender, "shake_completed")
6263
end)
64+
elseif message_id == STOP_SHAKING then
65+
camera.stop_shaking(go.get_id())
6366
end
6467
end

0 commit comments

Comments
 (0)