* fixed DSFML Sound3D example

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1434 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
trass3r 2010-03-02 13:45:46 +00:00
parent 914db8bce0
commit e394b6f35c

View File

@ -11,15 +11,16 @@ void main()
RenderWindow app = new RenderWindow (VideoMode(800, 600, 32), "Sound Spatialization Sample");
app.useVerticalSync(true);
Font f = new Font("Data/cheeseburger.ttf", 34);
Font f = new Font("Data/cheeseburger.ttf");
//Some instructions
String s = new String("Click anywhere on screen to change listener position.\nPress + or - to modify the speed of the car."c, f);
Text s = new Text("Click anywhere on screen to change listener position.\nPress + or - to modify the speed of the car."c, f);
s.setCharacterSize(34);
s.setPosition(20, 30);
s.setColor(Color.BLACK);
//We prepare our images and the sound
char[][2] images = ["Data/bluerallyecarleft.bmp", "Data/bluerallyecarright.bmp"];
string[2] images = ["Data/bluerallyecarleft.bmp", "Data/bluerallyecarright.bmp"];
Car c = new Car(images, "Data/car_idle.wav");
int carSpeed = 100;
@ -39,23 +40,23 @@ void main()
while (app.getEvent(evt))
{
// if the window is closed, we can leave the game loop
if (evt.Type == Event.EventType.CLOSED)
if (evt.Type == EventType.Closed)
app.close();
// we handle the click event to change listener position
else if (evt.Type == Event.EventType.MOUSEBUTTONPRESSED && evt.MouseButton.Button == MouseButtons.LEFT)
else if (evt.Type == EventType.MouseButtonPressed && evt.MouseButton.Button == MouseButtons.Left)
{
Input i = app.getInput();
SoundListener.setPosition(Vector2f(i.getMouseX(), i.getMouseY()));
}
// and eventual keys press
else if (evt.Type == Event.EventType.KEYPRESSED)
else if (evt.Type == EventType.KeyPressed)
{
//Change the car speed
if (evt.Key.Code == KeyCode.ADD)
if (evt.Key.Code == KeyCode.Add)
{
carSpeed += 25;
}
else if (evt.Key.Code == KeyCode.SUBTRACT)
else if (evt.Key.Code == KeyCode.Substract)
{
carSpeed -= 25;
}
@ -90,7 +91,7 @@ class SoundListener
crosshairImg.createMaskFromColor(Color.WHITE);
s_crosshair = new Sprite(crosshairImg);
s_crosshair.setCenter(Vector2f(s_crosshair.getSize().x / 2, s_crosshair.getSize().y / 2));
s_crosshair.setOrigin(Vector2f(s_crosshair.getSize().x / 2, s_crosshair.getSize().y / 2));
//Listener.setTarget(1.f, 0.f, 0.f);
}
@ -119,7 +120,7 @@ class Car
Image[2] imgs;
//Constructor with with a fixed size string array of image path, and a string for the sound path
this (char[][2] images, char[] soundFilename)
this (string[2] images, string soundFilename)
{
//load images and create filter
imgs[0] = new Image(images[0]); imgs[1] = new Image(images[1]);
@ -128,7 +129,7 @@ class Car
img.createMaskFromColor(Color(97, 68, 43));
m_sprite = new Sprite(imgs[0]);
m_sprite.setCenter(Vector2f(m_sprite.getSize().x / 2, m_sprite.getSize().y / 2));
m_sprite.setOrigin(Vector2f(m_sprite.getSize().x / 2, m_sprite.getSize().y / 2));
SoundBuffer buff = new SoundBuffer(soundFilename);