Created
June 5, 2012 13:17
-
-
Save notintricate/2874915 to your computer and use it in GitHub Desktop.
sequence playback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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,3 do | |
Textures[i] = Texture(scene:createObject(CID_TEXTURE)) | |
Textures[i]:setResource("./sequence/my_part_" .. 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