Difference between revisions of "Sound.setListenerPosition"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' in development<br/> === Description === Sets the position of the listener in a 3D environment <source lang="lua"> = Sound.setListenerPosition(...")
 
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''Available since:''' in development<br/>
+
'''Available since:''' Gideros 2016.10<br/>
 +
'''Class:''' [[Sound]]<br/>
 +
 
 
=== Description ===
 
=== Description ===
Sets the position of the listener in a 3D environment
+
Sets the position of the listener in a 3D environment.
<source lang="lua">
+
<syntaxhighlight lang="lua">
= Sound.setListenerPosition(xyzvxvyvzdxdydzuxuyuz,)
+
Sound.setListenerPosition(x,y,z,vx,vy,vz,dx,dy,dz,ux,uy,uz)
</source>
+
</syntaxhighlight>
'''x:''' (number) X coordinate of the listener ''''''<br/>
+
 
'''y:''' (number) Y coordinate of the listener ''''''<br/>
+
  '''Note''': please notice the '''dot''' instead of the column Sound'''.'''setListenerPosition(...)
'''z:''' (number) z coordinate of the listener '''optional'''<br/>
+
 
'''vx:''' (number) X component of listener's velocity '''optional'''<br/>
+
=== Parameters ===
'''vy:''' (number) Y component of listener's velocity '''optional'''<br/>
+
'''x''': (number) X coordinate of the listener<br/>
'''vz:''' (number) Z component of listener's velocity '''optional'''<br/>
+
'''y''': (number) Y coordinate of the listener<br/>
'''dx:''' (number) X component of the direction the listener is facing '''optional'''<br/>
+
'''z''': (number) z coordinate of the listener '''optional'''<br/>
'''dy:''' (number) Y component of the direction the listener is facing '''optional'''<br/>
+
'''vx''': (number) X component of listener's velocity '''optional'''<br/>
'''dz:''' (number) Z component of the direction the listener is facing '''optional'''<br/>
+
'''vy''': (number) Y component of listener's velocity '''optional'''<br/>
'''ux:''' (number) X component of up direction relative to the listener '''optional'''<br/>
+
'''vz''': (number) Z component of listener's velocity '''optional'''<br/>
'''uy:''' (number) Y component of up direction relative to the listener '''optional'''<br/>
+
'''dx''': (number) X component of the direction the listener is facing '''optional'''<br/>
'''uz:''' (number) Z component of up direction relative to the listener '''optional'''<br/>
+
'''dy''': (number) Y component of the direction the listener is facing '''optional'''<br/>
 +
'''dz''': (number) Z component of the direction the listener is facing '''optional'''<br/>
 +
'''ux''': (number) X component of up direction relative to the listener '''optional'''<br/>
 +
'''uy''': (number) Y component of up direction relative to the listener '''optional'''<br/>
 +
'''uz''': (number) Z component of up direction relative to the listener '''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 snd1=Sound.new("1.wav")
 +
dot1.sndchn=snd1:play(0,true,true)
 +
 
 +
local dots = {dot1}
 +
 
 +
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>
 +
 
 +
{{Sound}}

Latest revision as of 15:31, 13 July 2023

Available since: Gideros 2016.10
Class: Sound

Description

Sets the position of the listener in a 3D environment.

Sound.setListenerPosition(x,y,z,vx,vy,vz,dx,dy,dz,ux,uy,uz)
  Note: please notice the dot instead of the column Sound.setListenerPosition(...)

Parameters

x: (number) X coordinate of the listener
y: (number) Y coordinate of the listener
z: (number) z coordinate of the listener optional
vx: (number) X component of listener's velocity optional
vy: (number) Y component of listener's velocity optional
vz: (number) Z component of listener's velocity optional
dx: (number) X component of the direction the listener is facing optional
dy: (number) Y component of the direction the listener is facing optional
dz: (number) Z component of the direction the listener is facing optional
ux: (number) X component of up direction relative to the listener optional
uy: (number) Y component of up direction relative to the listener optional
uz: (number) Z component of up direction relative to the listener 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 snd1=Sound.new("1.wav")
dot1.sndchn=snd1:play(0,true,true)

local dots = {dot1}

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)