Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 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()
Add Comment
Please, Sign In to add comment