2014-07-26 20:49:29

Here is my side scroller panning code.
This is the best panning code that I've made.
Call this function with your x position and the observer x (the object
that is being listened) and the pygame volume value will be returned.
I tryed to make this code from the BGT code but... the other volume is
not changed and i don't know how to calculate this change, but at least
it is a bit realistic.
Code:
def distance_1d(x, observex, xstep):
    vol = [100, 100]
    speaker = -1
    if x > observex: # At right
        delta = x - observex
        speaker = 1
    elif observex > x: # At left
        delta = observex - x
        speaker = 0
    else:
        return 1.0
    delta *= xstep
    vol[speaker] -= delta
    lst = []
    for v in vol:
        if v <= 0:
            lst.append(0)
        else:
            lst.append(v*100*0.1*0.001)
    return lst
End code.
I'll try to do a pascal equivalent of this for people using the pure
SDL_mixer library on pascal.
If you want, feel free to post in any programming language that you want, as this
post is being archived in the forum, if someone searches and finds a
implementation in their favorite programming language it will be easyer for them.

2014-07-28 19:43:52

Here is the same function in pascal.
It is not a function because I don't know if returning an array will be
good so you pass the l and r variables in this procedure and when it returns these
variables will be filled with the volumes that needs to be set.
Note: This procedure is for SDL_mixer.
Code:
procedure distance_1d(x, observex, xstep: integer; var l, r: integer);
    var delta: integer;
    begin
    l := 255;
    r := 255;
    if (x > observex) then
        begin
        delta := x - observex;
        delta := delta * xstep;
        r := r - delta;
    end
    else if (observex > x) then
        begin
        delta := observex - x;
        delta := delta * xstep;
        l := l - delta;
    end
    else exit; { Return 255 for the two speakers }
    { Fix values }
    if (l < 0) then l := 0;
    if (r < 0) then r := 0;
end;
End code.

2015-03-07 07:51:04

ooh, that's strange, i will not sound proud to myself but i can't do anything at that problem.??


______________________


raza

raza