Difference between revisions of "SoundChannel:setWorldPosition"
From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>") |
|||
| (7 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
| − | ''' | + | '''Available since:''' Gideros 2016.10<br/> |
| − | === | + | '''Class:''' [[SoundChannel]]<br/> |
| − | + | ||
| − | < | + | === Description === |
| − | + | Sets the position of the sound in a 3D world. | |
| − | </ | + | <syntaxhighlight lang="lua"> |
| − | === | + | SoundChannel:setWorldPosition(x,y,z,vx,vy,vz) |
| − | '''x''': (number) | + | </syntaxhighlight> |
| − | '''y''': (number) | + | |
| − | '''z''': (number) | + | === Parameters === |
| − | '''vx''': (number) | + | '''x''': (number) sound x coordinate<br/> |
| − | '''vy''': (number) | + | '''y''': (number) sound y coordinate<br/> |
| − | '''vz''': (number) | + | '''z''': (number) sound z coordinate '''optional'''<br/> |
| + | '''vx''': (number) sound velocity x component '''optional'''<br/> | ||
| + | '''vy''': (number) sound velocity y component '''optional'''<br/> | ||
| + | '''vz''': (number) sound velocity z component '''optional'''<br/> | ||
| + | |||
| + | === Example === | ||
| + | <syntaxhighlight lang="lua"> | ||
| + | local audioScale=0.02 | ||
| + | local scrW,scrH=application:getContentWidth(),application:getContentHeight() | ||
| + | Sound.setListenerPosition(scrW*audioScale/2,scrH*audioScale/2,0,0,0,0,0,1,0,0,0,1) | ||
| + | |||
| + | local dot1 = Bitmap.new(Texture.new("1.png")) | ||
| + | dot1:setAnchorPoint(0.5, 0.5) | ||
| + | |||
| + | local dot2 = Bitmap.new(Texture.new("2.png")) | ||
| + | dot2:setAnchorPoint(0.5, 0.5) | ||
| + | |||
| + | local snd1=Sound.new("1.wav") | ||
| + | dot1.sndchn=snd1:play(0,true,true) | ||
| + | local snd2=Sound.new("2.wav") | ||
| + | dot2.sndchn=snd2:play(0,true,true) | ||
| + | |||
| + | local dots = {dot1, dot2} | ||
| + | |||
| + | local function onTouchesBegin(event) | ||
| + | local dot = dots[event.touch.id] | ||
| + | if dot then | ||
| + | stage:addChild(dot) | ||
| + | dot:setPosition(event.touch.x, event.touch.y) | ||
| + | dot.sndchn:setWorldPosition(event.touch.x*audioScale, event.touch.y*audioScale) | ||
| + | dot.sndchn:setPaused(false) | ||
| + | end | ||
| + | end | ||
| + | |||
| + | local function onTouchesMove(event) | ||
| + | local dot = dots[event.touch.id] | ||
| + | if dot then | ||
| + | dot:setPosition(event.touch.x, event.touch.y) | ||
| + | dot.sndchn:setWorldPosition(event.touch.x*audioScale, event.touch.y*audioScale) | ||
| + | end | ||
| + | end | ||
| + | |||
| + | local function onTouchesEnd(event) | ||
| + | local dot = dots[event.touch.id] | ||
| + | if dot and stage:contains(dot) then | ||
| + | stage:removeChild(dot) | ||
| + | dot.sndchn:setPaused(true) | ||
| + | end | ||
| + | end | ||
| + | |||
| + | local function onTouchesCancel(event) | ||
| + | local dot = dots[event.touch.id] | ||
| + | if dot and stage:contains(dot) then | ||
| + | stage:removeChild(dot) | ||
| + | dot.sndchn:setPaused(true) | ||
| + | end | ||
| + | end | ||
| + | |||
| + | stage:addEventListener(Event.TOUCHES_BEGIN, onTouchesBegin) | ||
| + | stage:addEventListener(Event.TOUCHES_MOVE, onTouchesMove) | ||
| + | stage:addEventListener(Event.TOUCHES_END, onTouchesEnd) | ||
| + | stage:addEventListener(Event.TOUCHES_CANCEL, onTouchesCancel) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | {{SoundChannel}} | ||
Latest revision as of 14:33, 13 July 2023
Available since: Gideros 2016.10
Class: SoundChannel
Description
Sets the position of the sound in a 3D world.
SoundChannel:setWorldPosition(x,y,z,vx,vy,vz)
Parameters
x: (number) sound x coordinate
y: (number) sound y coordinate
z: (number) sound z coordinate optional
vx: (number) sound velocity x component optional
vy: (number) sound velocity y component optional
vz: (number) sound velocity z component optional
Example
local audioScale=0.02
local scrW,scrH=application:getContentWidth(),application:getContentHeight()
Sound.setListenerPosition(scrW*audioScale/2,scrH*audioScale/2,0,0,0,0,0,1,0,0,0,1)
local dot1 = Bitmap.new(Texture.new("1.png"))
dot1:setAnchorPoint(0.5, 0.5)
local dot2 = Bitmap.new(Texture.new("2.png"))
dot2:setAnchorPoint(0.5, 0.5)
local snd1=Sound.new("1.wav")
dot1.sndchn=snd1:play(0,true,true)
local snd2=Sound.new("2.wav")
dot2.sndchn=snd2:play(0,true,true)
local dots = {dot1, dot2}
local function onTouchesBegin(event)
local dot = dots[event.touch.id]
if dot then
stage:addChild(dot)
dot:setPosition(event.touch.x, event.touch.y)
dot.sndchn:setWorldPosition(event.touch.x*audioScale, event.touch.y*audioScale)
dot.sndchn:setPaused(false)
end
end
local function onTouchesMove(event)
local dot = dots[event.touch.id]
if dot then
dot:setPosition(event.touch.x, event.touch.y)
dot.sndchn:setWorldPosition(event.touch.x*audioScale, event.touch.y*audioScale)
end
end
local function onTouchesEnd(event)
local dot = dots[event.touch.id]
if dot and stage:contains(dot) then
stage:removeChild(dot)
dot.sndchn:setPaused(true)
end
end
local function onTouchesCancel(event)
local dot = dots[event.touch.id]
if dot and stage:contains(dot) then
stage:removeChild(dot)
dot.sndchn:setPaused(true)
end
end
stage:addEventListener(Event.TOUCHES_BEGIN, onTouchesBegin)
stage:addEventListener(Event.TOUCHES_MOVE, onTouchesMove)
stage:addEventListener(Event.TOUCHES_END, onTouchesEnd)
stage:addEventListener(Event.TOUCHES_CANCEL, onTouchesCancel)
- SoundChannel:getPitch
- SoundChannel:getPosition
- SoundChannel:getStreamId
- SoundChannel:getVolume
- SoundChannel:isLooping
- SoundChannel:isPaused
- SoundChannel:isPlaying
- SoundChannel:setEffect
- SoundChannel:setLooping
- SoundChannel:setPaused
- SoundChannel:setPitch
- SoundChannel:setPosition
- SoundChannel:setVolume
- SoundChannel:setWorldPosition
- SoundChannel:stop