mirror of
https://github.com/defold/extension-camera
synced 2025-09-27 17:02:19 +02:00
Additional state handling cleanup
This commit is contained in:
@@ -17,11 +17,10 @@ local function start_capture(self)
|
||||
return
|
||||
end
|
||||
|
||||
local sysinfo = sys.get_sys_info()
|
||||
|
||||
local quality = camera.CAPTURE_QUALITY_HIGH
|
||||
|
||||
local type = camera.CAMERA_TYPE_FRONT
|
||||
if sysinfo.system_name == 'iPhone OS' then
|
||||
if sys.get_sys_info().system_name == 'iPhone OS' then
|
||||
type = camera.CAMERA_TYPE_BACK
|
||||
quality = camera.CAPTURE_QUALITY_MEDIUM
|
||||
end
|
||||
@@ -30,11 +29,13 @@ local function start_capture(self)
|
||||
if status == camera.STATUS_STARTED then
|
||||
self.cameraframe = camera.get_frame()
|
||||
self.camerainfo = camera.get_info()
|
||||
self.cameratextureheader = {width=self.camerainfo.width,
|
||||
height=self.camerainfo.height,
|
||||
type=resource.TEXTURE_TYPE_2D,
|
||||
format=resource.TEXTURE_FORMAT_RGB,
|
||||
num_mip_maps=1 }
|
||||
self.cameratextureheader = {
|
||||
width=self.camerainfo.width,
|
||||
height=self.camerainfo.height,
|
||||
type=resource.TEXTURE_TYPE_2D,
|
||||
format=resource.TEXTURE_FORMAT_RGB,
|
||||
num_mip_maps=1
|
||||
}
|
||||
label.set_text("logo#status", "Capture Status: ON")
|
||||
else
|
||||
label.set_text("logo#status", "Capture Status: ERROR")
|
||||
@@ -53,19 +54,18 @@ function init(self)
|
||||
|
||||
go.set("#sprite", "scale", vmath.vector3(scale_width, scale_height, 1) )
|
||||
|
||||
|
||||
start_capture(self)
|
||||
end
|
||||
|
||||
function final(self)
|
||||
if self.cameraframe ~= nil then
|
||||
if self.cameraframe then
|
||||
camera.stop_capture()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function update(self, dt)
|
||||
if self.cameraframe ~= nil then
|
||||
if self.cameraframe then
|
||||
local pathmodelcamera = go.get("#sprite", "texture0")
|
||||
resource.set_texture(pathmodelcamera, self.cameratextureheader, self.cameraframe)
|
||||
end
|
||||
@@ -74,10 +74,10 @@ end
|
||||
|
||||
function on_input(self, action_id, action)
|
||||
if (action_id == hash("space") or action_id == hash("touch")) and action.pressed then
|
||||
if self.cameraframe == nil then
|
||||
start_capture(self)
|
||||
else
|
||||
if self.cameraframe then
|
||||
stop_capture(self)
|
||||
else
|
||||
start_capture(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user