2DAudio.lua 915 B

12345678910111213141516171819202122232425262728
  1. screen = Screen()
  2. sourceEntity = ScreenEntity()
  3. testSound = ScreenSound("test.wav", 200, 600)
  4. testSound:getSound():Play(true)
  5. sourceEntity:addChild(testSound)
  6. soundShape = ScreenShape(SHAPE_CIRCLE, 20,20,10)
  7. sourceEntity:addChild(soundShape)
  8. screen:addChild(sourceEntity)
  9. listenerEntity = ScreenEntity()
  10. soundListener = ScreenSoundListener()
  11. listenerEntity:addChild(soundListener)
  12. soundShape = ScreenShape(SHAPE_CIRCLE, 20,20,10)
  13. soundShape:setColor(0.0, 1.0, 0.0, 1.0)
  14. listenerEntity:addChild(soundShape)
  15. screen:addChild(listenerEntity)
  16. listenerPositionValue = 0
  17. positionValue = 0
  18. function Update(elapsed)
  19. positionValue = positionValue + elapsed
  20. listenerPositionValue = listenerPositionValue + elapsed * 0.3
  21. sourceEntity:setPosition(300 + (sin(positionValue) * 300), 250 + cos(positionValue) * 100)
  22. listenerEntity:setPosition(300 + (sin(listenerPositionValue) * 300), 250)
  23. end