fixed 2 samples, thx AndrejM
sound3d sample compiles but sound stops after some time git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1553 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
64b4bd8472
commit
9da487ac13
@ -15,9 +15,10 @@ void main()
|
|||||||
|
|
||||||
//Some instructions
|
//Some instructions
|
||||||
Text s = new Text("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.characterSize = 34;
|
||||||
s.setPosition(20, 30);
|
s.setPosition(20, 30);
|
||||||
s.setColor(Color.BLACK);
|
s.color = Color.BLACK;
|
||||||
|
|
||||||
//We prepare our images and the sound
|
//We prepare our images and the sound
|
||||||
string[2] images = ["Data/bluerallyecarleft.bmp", "Data/bluerallyecarright.bmp"];
|
string[2] images = ["Data/bluerallyecarleft.bmp", "Data/bluerallyecarright.bmp"];
|
||||||
@ -26,8 +27,8 @@ void main()
|
|||||||
int carSpeed = 100;
|
int carSpeed = 100;
|
||||||
|
|
||||||
//Set default position for the car and the listener
|
//Set default position for the car and the listener
|
||||||
c.setPosition(Vector2f(0, 300));
|
c.position = Vector2f(0, 300);
|
||||||
SoundListener.setPosition(Vector2f(400, 300));
|
SoundListener.position = Vector2f(400, 300);
|
||||||
|
|
||||||
c.startPlaying();
|
c.startPlaying();
|
||||||
|
|
||||||
@ -45,8 +46,8 @@ void main()
|
|||||||
// we handle the click event to change listener position
|
// we handle the click event to change listener position
|
||||||
else if (evt.Type == EventType.MouseButtonPressed && evt.MouseButton.Button == MouseButtons.Left)
|
else if (evt.Type == EventType.MouseButtonPressed && evt.MouseButton.Button == MouseButtons.Left)
|
||||||
{
|
{
|
||||||
Input i = app.getInput();
|
Input i = app.input;
|
||||||
SoundListener.setPosition(Vector2f(i.getMouseX(), i.getMouseY()));
|
SoundListener.position = Vector2f(i.mouseX, i.mouseY);
|
||||||
}
|
}
|
||||||
// and eventual keys press
|
// and eventual keys press
|
||||||
else if (evt.Type == EventType.KeyPressed)
|
else if (evt.Type == EventType.KeyPressed)
|
||||||
@ -64,12 +65,12 @@ void main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//We move constantly our car.
|
//We move constantly our car.
|
||||||
c.move(Vector2f(app.getFrameTime() * carSpeed, 0));
|
c.move(Vector2f(app.frameTime * carSpeed, 0));
|
||||||
|
|
||||||
//Draw all the sprite and string on render window
|
//Draw all the sprite and string on render window
|
||||||
app.draw(s);
|
app.draw(s);
|
||||||
app.draw(c.getSprite());
|
app.draw(c.sprite);
|
||||||
app.draw(SoundListener.getSprite());
|
app.draw(SoundListener.sprite);
|
||||||
|
|
||||||
//And finally display the window
|
//And finally display the window
|
||||||
app.display();
|
app.display();
|
||||||
@ -91,26 +92,26 @@ class SoundListener
|
|||||||
crosshairImg.createMaskFromColor(Color.WHITE);
|
crosshairImg.createMaskFromColor(Color.WHITE);
|
||||||
|
|
||||||
s_crosshair = new Sprite(crosshairImg);
|
s_crosshair = new Sprite(crosshairImg);
|
||||||
s_crosshair.setOrigin(Vector2f(s_crosshair.getSize().x / 2, s_crosshair.getSize().y / 2));
|
s_crosshair.setOrigin(s_crosshair.size.x / 2, s_crosshair.size.y / 2);
|
||||||
|
|
||||||
//Listener.setTarget(1.f, 0.f, 0.f);
|
//Listener.setTarget(1.f, 0.f, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust position of the listener
|
// Adjust position of the listener
|
||||||
static void setPosition(Vector2f p)
|
@property static void position(Vector2f p)
|
||||||
{
|
{
|
||||||
Listener.setPosition(p.x, p.y, 5.f);
|
Listener.setPosition(p.x, p.y, 5.f);
|
||||||
s_crosshair.setPosition(p);
|
s_crosshair.setPosition(p.x, p.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Sprite getSprite()
|
@property static Sprite sprite()
|
||||||
{
|
{
|
||||||
return s_crosshair;
|
return s_crosshair;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Class encapsulating all data for our car
|
//! Class encapsulating all data for our car
|
||||||
class Car
|
class Car
|
||||||
{
|
{
|
||||||
Vector2f m_actual;
|
Vector2f m_actual;
|
||||||
@ -129,13 +130,13 @@ class Car
|
|||||||
img.createMaskFromColor(Color(97, 68, 43));
|
img.createMaskFromColor(Color(97, 68, 43));
|
||||||
|
|
||||||
m_sprite = new Sprite(imgs[0]);
|
m_sprite = new Sprite(imgs[0]);
|
||||||
m_sprite.setOrigin(Vector2f(m_sprite.getSize().x / 2, m_sprite.getSize().y / 2));
|
m_sprite.setOrigin(m_sprite.size.x / 2, m_sprite.size.y / 2);
|
||||||
|
|
||||||
SoundBuffer buff = new SoundBuffer(soundFilename);
|
SoundBuffer buff = new SoundBuffer(soundFilename);
|
||||||
|
|
||||||
//load our sound with loop enabled
|
//load our sound with loop enabled
|
||||||
m_sound = new Sound(buff, true);
|
m_sound = new Sound(buff, true);
|
||||||
m_sound.setAttenuation(.05f);
|
m_sound.attenuation = .05f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin the sound play
|
// Begin the sound play
|
||||||
@ -146,9 +147,9 @@ class Car
|
|||||||
|
|
||||||
// Set the position of the car on the window
|
// Set the position of the car on the window
|
||||||
// Used to setup the begin car window and sound location
|
// Used to setup the begin car window and sound location
|
||||||
void setPosition(Vector2f p)
|
@property void position(Vector2f p)
|
||||||
{
|
{
|
||||||
m_sprite.setPosition(p);
|
m_sprite.setPosition(p.x, p.y);
|
||||||
m_sound.setPosition(p.x, 0, p.y);
|
m_sound.setPosition(p.x, 0, p.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,13 +158,13 @@ class Car
|
|||||||
void move(Vector2f vec)
|
void move(Vector2f vec)
|
||||||
{
|
{
|
||||||
// if the car is beyond the right screen limit
|
// if the car is beyond the right screen limit
|
||||||
if (!reverse && m_sprite.getPosition().x > 850)
|
if (!reverse && m_sprite.position.x > 850)
|
||||||
{
|
{
|
||||||
m_sprite.setImage(imgs[1]);
|
m_sprite.setImage(imgs[1]);
|
||||||
reverse = true;
|
reverse = true;
|
||||||
}
|
}
|
||||||
// same as above but for left limit
|
// same as above but for left limit
|
||||||
else if (reverse && vec.x + m_sprite.getPosition().x < -50)
|
else if (reverse && vec.x + m_sprite.position.x < -50)
|
||||||
{
|
{
|
||||||
m_sprite.setImage(imgs[0]);
|
m_sprite.setImage(imgs[0]);
|
||||||
reverse = false;
|
reverse = false;
|
||||||
@ -173,19 +174,12 @@ class Car
|
|||||||
vec = -vec;
|
vec = -vec;
|
||||||
|
|
||||||
m_sprite.move(vec);
|
m_sprite.move(vec);
|
||||||
Vector2f pos = m_sprite.getPosition();
|
Vector2f pos = m_sprite.position;
|
||||||
m_sound.setPosition(pos.x , pos.y, 0);
|
m_sound.setPosition(pos.x , pos.y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite getSprite()
|
@property Sprite sprite()
|
||||||
{
|
{
|
||||||
return m_sprite;
|
return m_sprite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -7,10 +7,10 @@ import dsfml.graphics.all;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
RenderWindow window = new RenderWindow(VideoMode(800, 600), "View sample");
|
RenderWindow window = new RenderWindow(VideoMode(800, 600), "View sample");
|
||||||
window.setFramerateLimit(100);
|
window.framerateLimit = 100;
|
||||||
Input input = window.getInput();
|
Input input = window.input;
|
||||||
Vector2f top;
|
Vector2f top;
|
||||||
Rect!(float) bound;
|
FloatRect bound;
|
||||||
Shape s;
|
Shape s;
|
||||||
bool mousePressed;
|
bool mousePressed;
|
||||||
|
|
||||||
@ -28,33 +28,33 @@ void main()
|
|||||||
if ( evt.Type == EventType.MouseButtonPressed &&
|
if ( evt.Type == EventType.MouseButtonPressed &&
|
||||||
evt.MouseButton.Button == MouseButtons.Left)
|
evt.MouseButton.Button == MouseButtons.Left)
|
||||||
{
|
{
|
||||||
top = window.convertCoords(input.getMouseX(), input.getMouseY());
|
top = window.convertCoords(input.mouseX, input.mouseY);
|
||||||
mousePressed = true;
|
mousePressed = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( evt.Type == EventType.MouseButtonReleased &&
|
else if ( evt.Type == EventType.MouseButtonReleased &&
|
||||||
evt.MouseButton.Button == MouseButtons.Left)
|
evt.MouseButton.Button == MouseButtons.Left)
|
||||||
{
|
{
|
||||||
mousePressed = false;
|
mousePressed = false;
|
||||||
}
|
}
|
||||||
else if ( evt.Type == EventType.MouseMoved &&
|
else if ( evt.Type == EventType.MouseMoved &&
|
||||||
mousePressed)
|
mousePressed)
|
||||||
{
|
{
|
||||||
Vector2f bottom = window.convertCoords(input.getMouseX(), input.getMouseY());
|
Vector2f bottom = window.convertCoords(input.mouseX, input.mouseY);
|
||||||
bound = FloatRect(top.x, top.y, bottom.x, bottom.y);
|
bound = FloatRect(top.x, top.y, bottom.x-top.x, bottom.y-top.y);
|
||||||
s = Shape.rectangle(top.x, top.y, bottom.x, bottom.y, Color(0, 0, 0, 0), 1, Color.BLACK);
|
s = Shape.rectangle(bound.left, bound.top, bound.width, bound.height, Color(0, 0, 0, 0), 1, Color.BLACK);
|
||||||
}
|
}
|
||||||
else if ( evt.Type == EventType.KeyPressed &&
|
else if ( evt.Type == EventType.KeyPressed &&
|
||||||
evt.Key.Code == KeyCode.Return)
|
evt.Key.Code == KeyCode.Return)
|
||||||
{
|
{
|
||||||
if (bound != FloatRect())
|
if (bound != FloatRect())
|
||||||
window.setView(new View(bound));
|
window.view = new View(bound);
|
||||||
s = null;
|
s = null;
|
||||||
}
|
}
|
||||||
else if ( evt.Type == EventType.KeyPressed &&
|
else if ( evt.Type == EventType.KeyPressed &&
|
||||||
evt.Key.Code == KeyCode.Escape)
|
evt.Key.Code == KeyCode.Escape)
|
||||||
{
|
{
|
||||||
window.setView(window.getDefaultView());
|
window.view = window.defaultView;
|
||||||
}
|
}
|
||||||
else if ( evt.Type == EventType.Closed)
|
else if ( evt.Type == EventType.Closed)
|
||||||
window.close();
|
window.close();
|
||||||
@ -66,4 +66,4 @@ void main()
|
|||||||
if (s !is null) window.draw(s);
|
if (s !is null) window.draw(s);
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user