2DAudio.lua 988 B

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