Guest User

Untitled

a guest
Oct 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. -- access to the scene objects
  2. local scene = getCurrentScene()
  3.  
  4. -- define keyboard input
  5. local inputManager = getInputManager()
  6. local keyboard = Keyboard(inputManager:getDevice(TIINPUT_KEYBOARDDEVICE))
  7.  
  8. -- dynamically create the texture objects for image sequence
  9. local Textures = {}
  10.  
  11. local function CreateTextures()
  12. for i=1,3 do
  13. Textures[i] = Texture(scene:createObject(CID_TEXTURE))
  14. Textures[i]:setResource("./sequence/my_part_" .. i-1 .. ".png")
  15. end
  16. end
  17.  
  18. CreateTextures()
  19.  
  20. -- apply first image on the TV material
  21. local tv_video_material = getMaterial("tv/video")
  22. tv_video_material:setTexture(Textures[1])
  23.  
  24. -- initial parameters
  25. local video_playing = false
  26. local current_texture = 1
  27.  
  28. -- control the image sequence
  29. repeat
  30.  
  31. -- control the video status with the keyboard
  32. if keyboard:wasKeyPressed(TIKEYBOARD_1) or keyboard:wasKeyPressed(TIKEYBOARD_NUMPAD1) then
  33. -- play/pause video
  34. if not video_playing then video_playing = true else video_playing = false end
  35.  
  36. elseif keyboard:wasKeyPressed(TIKEYBOARD_2) or keyboard:wasKeyPressed(TIKEYBOARD_NUMPAD2) then
  37. -- restart video
  38. current_texture = 1
  39. if not video_playing then video_playing = true end
  40.  
  41. end
  42.  
  43. -- control the iamge sequence according to the pressed key
  44. if video_playing then
  45. current_texture = current_texture + 1
  46. tv_video_material:setTexture(Textures[current_texture])
  47. if current_texture > 2 then current_texture = 1 end
  48. end
  49.  
  50. until coroutine.yield()
Add Comment
Please, Sign In to add comment