Difference between revisions of "Source:setRelative"

m (Fixed)
(Made description more clear and added an example.)
Line 1: Line 1:
 
{{newin|[[0.9.0]]|090|type=function}}
 
{{newin|[[0.9.0]]|090|type=function}}
Sets whether the Source's position, velocity, direction, and cone angles are relative to the listener.
+
Sets whether the [[parent::Source]]'s position, velocity, direction, and cone angles are relative to the listener, or absolute.
 +
 
 +
By default, all sources are absolute and therefore relative to the origin of love's coordinate system [0, 0, 0]. Only absolute sources are affected by the position of the listener.
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 7: Line 9:
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|boolean|enable|True to make the position, velocity, direction and cone angles relative to the listener, false to make them absolute.}}
+
{{param|boolean|enable ("false")|True to make the position, velocity, direction and cone angles relative to the listener, false to make them absolute.}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
=== Absolute Source Demonstration ===
 +
This example demonstrates how an absolute source is affected by the position of the listener.
 +
<source lang="lua">
 +
-- The position of the listener.
 +
local x, y, z;
 +
 +
-- The sound to play.
 +
local snd;
 +
 +
function love.load()
 +
    snd = love.audio.newSource('example.ogg', 'static')
 +
    snd:setRelative(false); -- Make the sound'absolute'.
 +
    snd:setLooping(true);
 +
    snd:play();
 +
 +
    -- Set the position of the listener and the source to the middle of the screen.
 +
    x = love.graphics.getWidth() * 0.5;
 +
    y = love.graphics.getHeight() * 0.5;
 +
    z = 0;
 +
    love.audio.setPosition(x, y, z);
 +
    snd:setPosition(x, y, z);
 +
end
 +
 +
-- Move the listener to the left ('a') or to the right ('d').
 +
function love.keypressed(key)
 +
    if key == 'a' then
 +
        x = x - 1;
 +
        love.audio.setPosition(x, y, z);
 +
    elseif key == 'd' then
 +
        x = x + 1;
 +
        love.audio.setPosition(x, y, z);
 +
    end
 +
end
 +
</source>
 
== See Also ==
 
== See Also ==
 
* [[parent::Source]]
 
* [[parent::Source]]

Revision as of 15:24, 30 September 2014

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Sets whether the Source's position, velocity, direction, and cone angles are relative to the listener, or absolute.

By default, all sources are absolute and therefore relative to the origin of love's coordinate system [0, 0, 0]. Only absolute sources are affected by the position of the listener.

Function

Synopsis

Source:setRelative( enable )

Arguments

boolean enable ("false")
True to make the position, velocity, direction and cone angles relative to the listener, false to make them absolute.

Returns

Nothing.

Absolute Source Demonstration

This example demonstrates how an absolute source is affected by the position of the listener.

-- The position of the listener.
local x, y, z;

-- The sound to play.
local snd;

function love.load()
    snd = love.audio.newSource('example.ogg', 'static')
    snd:setRelative(false); -- Make the sound'absolute'.
    snd:setLooping(true);
    snd:play();

    -- Set the position of the listener and the source to the middle of the screen.
    x = love.graphics.getWidth() * 0.5;
    y = love.graphics.getHeight() * 0.5;
    z = 0;
    love.audio.setPosition(x, y, z);
    snd:setPosition(x, y, z);
end

-- Move the listener to the left ('a') or to the right ('d').
function love.keypressed(key)
    if key == 'a' then
        x = x - 1;
        love.audio.setPosition(x, y, z);
    elseif key == 'd' then
        x = x + 1;
        love.audio.setPosition(x, y, z);
    end
end

See Also

Other Languages