Skip to content

Commit

Permalink
Added stop_shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Feb 4, 2018
1 parent 9837b15 commit fd968ab
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ Shake the camera.
* ```direction``` (hash) - Direction of the shake. Possible values: ```both```, ```horizontal```, ```vertical```. Defaults to ```both```.
* ```cb``` (function) - Function to call when the shake has finished. Optional.

### camera.stop_shaing(camera_id)
Stop shaking the camera.

**PARAMETERS**
* ```camera_id``` (hash|url)

### camera.follow(camera_id, target, [lerp])
Follow a game object.

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

### stop_shaking
Message equivalent to ```camera.stop_shaking()```.

### shake_complete
Message sent back to the sender of a ```shake``` message when the shake has completed.

Expand Down
159 changes: 159 additions & 0 deletions example/camera_controls.gui
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,165 @@ nodes {
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 513.154
y: 84.266
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEMPLATE
id: "stop_shaking"
parent: "buttons"
layer: ""
inherit_alpha: true
alpha: 1.0
template: "/example/assets/button.gui"
template_node_child: false
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 100.0
y: 40.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "main/space"
id: "stop_shaking/button"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "stop_shaking"
layer: "below"
inherit_alpha: true
slice9 {
x: 4.0
y: 4.0
z: 4.0
w: 4.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 90.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "STOP SHAKING"
font: "silkscreen"
id: "stop_shaking/text"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: true
parent: "stop_shaking/button"
layer: "text"
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
overridden_fields: 8
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 640.0
Expand Down
2 changes: 2 additions & 0 deletions example/camera_controls.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function on_input(self, action_id, action)
msg.post("camera", "shake", { intensity = 0.05, duration = 0.5, direction = hash("horizontal") })
elseif gui.pick_node(gui.get_node("shake_vertical/button"), action.x, action.y) then
msg.post("camera", "shake", { intensity = 0.05, duration = 0.5, direction = hash("vertical") })
elseif gui.pick_node(gui.get_node("stop_shaking/button"), action.x, action.y) then
msg.post("camera", "stop_shaking")
elseif gui.pick_node(gui.get_node("bounds/button"), action.x, action.y) then
self.bounds_enabled = not self.bounds_enabled
if self.bounds_enabled then
Expand Down
9 changes: 9 additions & 0 deletions orthographic/camera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ function M.shake(camera_id, intensity, duration, direction, cb)
end



--- Stop shaking a camera
-- @param camera_id
function M.stop_shaking(camera_id)
assert(camera_id, "You must provide a camera id")
cameras[camera_id].shake = nil
end


--- Get the projection matrix for a camera
-- @param camera_id
-- @return Projection matrix
Expand Down
3 changes: 3 additions & 0 deletions orthographic/camera.script
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local DISABLE = hash("disable")
local UNFOLLOW = hash("unfollow")
local FOLLOW = hash("follow")
local SHAKE = hash("shake")
local STOP_SHAKING = hash("stop_shaking")
local DEADZONE = hash("deadzone")
local BOUNDS = hash("bounds")
local UPDATE_CAMERA = hash("update_camera")
Expand Down Expand Up @@ -60,5 +61,7 @@ function on_message(self, message_id, message, sender)
camera.shake(go.get_id(), message.intensity, message.duration, message.direction, function()
msg.post(sender, "shake_completed")
end)
elseif message_id == STOP_SHAKING then
camera.stop_shaking(go.get_id())
end
end

0 comments on commit fd968ab

Please sign in to comment.