Skip to content

Instantly share code, notes, and snippets.

@smakhtin
Forked from notintricate/sequence.lua
Created June 5, 2012 13:35
Show Gist options
  • Save smakhtin/2875040 to your computer and use it in GitHub Desktop.
Save smakhtin/2875040 to your computer and use it in GitHub Desktop.
sequence playback
-- access to the scene objects
local scene = getCurrentScene()
-- define keyboard input
local inputManager = getInputManager()
local keyboard = Keyboard(inputManager:getDevice(TIINPUT_KEYBOARDDEVICE))
-- dynamically create the texture objects for image sequence
local Textures = {}
local function CreateTextures()
for i=1,250 do
Textures[i] = Texture(scene:createObject(CID_TEXTURE))
Textures[i]:setResource("./sequence/my_part_" .. "00" .. i-1 .. ".png")
end
end
CreateTextures()
-- apply first image on the TV material
local tv_video_material = getMaterial("tv/video")
tv_video_material:setTexture(Textures[1])
-- initial parameters
local video_playing = false
local current_texture = 1
-- control the image sequence
repeat
-- control the video status with the keyboard
if keyboard:wasKeyPressed(TIKEYBOARD_1) or keyboard:wasKeyPressed(TIKEYBOARD_NUMPAD1) then
-- play/pause video
if not video_playing then video_playing = true else video_playing = false end
elseif keyboard:wasKeyPressed(TIKEYBOARD_2) or keyboard:wasKeyPressed(TIKEYBOARD_NUMPAD2) then
-- restart video
current_texture = 1
if not video_playing then video_playing = true end
end
-- control the iamge sequence according to the pressed key
if video_playing then
current_texture = current_texture + 1
tv_video_material:setTexture(Textures[current_texture])
if current_texture > 2 then current_texture = 1 end
end
until coroutine.yield()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment