1
Graphics / Outline inside of Shape::Rectangle
« on: November 27, 2009, 09:12:20 am »
Ok thanks
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
sf::Shape rect = sf::Shape::Rectangle(0, 0, 50, 50,<color_here>, 2.0f, <color_here>);
Shape blocksPanel = Shape::Rectangle(
(GRID_WIDTH + 2) * BLOCK_SIZE,
BLOCK_SIZE * 8,
(GRID_WIDTH + 7) * BLOCK_SIZE,
(GRID_HEIGHT_LIMIT + 1) * BLOCK_SIZE,
BG_COLOR,
OUTLINE,
OUTLINE_COLOR);
window->Draw(blocksPanel);
RenderWindow *window;
VideoMode mode(GUI_WIDTH, GUI_HEIGHT, 32);
window = new RenderWindow(mode, "Falling Blocks", Style::Close);
int main() {
Gui gui;
while (gui.isRunning()) {
gui.clearBackground(); // window.clear()
gui.defaultMove(); // move the object 1 space down
gui.handleEvents(); // the while loop i saw in the tutorials
gui.drawGamePanel(); // draw objects here
gui.display(); // window.display()
}
return 0;
}
int main() {
Gui gui;
while (gui.isRunning()) {
gui.clearBackground(); // window.clear()
// gui.defaultMove(); // move the object 1 space down
gui.handleEvents(); // the while loop i saw in the tutorials
// gui.drawGamePanel(); // draw objects here
gui.display(); // window.display()
}
return 0;
}
int main() {
Gui gui;
while (gui.isRunning()) {
Sleep(0.001f);
gui.clearBackground(); // window.clear()
gui.defaultMove(); // move the object 1 space down
gui.handleEvents(); // the while loop i saw in the tutorials
gui.drawGamePanel(); // draw objects here
gui.display(); // window.display()
}
return 0;
}
void Gui::handleEvents() {
//listen for events
Event event;
while (window->GetEvent(event)) {
// a key is pressed
if (event.Type == Event::KeyPressed) {
switch (event.Key.Code) {
case Key::Escape:
if (gameStatus == STATUS_PLAYING) {
cout << "pausing game..." << endl;
gameStatus = STATUS_PAUSED;
} else if (gameStatus == STATUS_PAUSED) {
cout << "resuming game..." << endl;
gameStatus = STATUS_PLAYING;
} else {
cout << "closing window..." << endl;
running = false;
window->Close();
}
break;
case Key::Left:
if (gameStatus == STATUS_PLAYING) {
current_shape->moveLeft();
}
break;
case Key::Right:
if (gameStatus == STATUS_PLAYING) {
current_shape->moveRight();
}
break;
case Key::Down:
if (gameStatus == STATUS_PLAYING) {
moveDown();
}
break;
case Key::Space:
if (gameStatus == STATUS_PLAYING) {
current_shape->rotateClockwise();
}
break;
default:
cout << "ignoring pressed key..." << endl;
}
} else if (event.Type == Event::Closed) {
cout << "pressed close button, closing window..." << endl;
running = false;
window->Close();
}
}
}
void Gui::defaultMove() {
//move shape down if status is STATUS_PLAYING
if ((clock.GetElapsedTime() >= sleepTime) && (gameStatus == STATUS_PLAYING)) {
clock.Reset();
moveDown();
}
}
int main() {
Gui gui;
while (gui.isRunning()) {
gui.clearBackground(); // window.clear()
gui.defaultMove(); // move the object 1 space down
gui.handleEvents(); // the while loop i saw in the tutorials
gui.drawGamePanel(); // draw objects here
gui.display(); // window.display()
}
return 0;
}
VideoMode mode(GUI_WIDTH, GUI_HEIGHT, 32);
window = new RenderWindow(mode, "Falling Blocks", Style::Close);
window->SetFramerateLimit(60);
Image img_icon;
img_icon.LoadFromFile("icon.png");
window->SetIcon( img_icon.GetWidth(), img_icon.GetHeight(), img_icon.GetPixelsPtr());
if (!font.LoadFromFile("myfont.ttf")) {
cout << "failed to load font" << endl;
return;
}
It's fixed in the sfml2 branch. It's not fixed in SFML 1.x because it requires a rewrite of the OpenGL context handling.
There are two very simple workarounds:
- link to the static versions of the SFML libraries
- always provide your own sf::Font when instanciating a sf::String
int main() {
cout << "Starting..." << endl;
WindowSettings settings;
settings.DepthBits = 32;
settings.StencilBits = 8;
settings.AntialiasingLevel = 2;
VideoMode mode(100, 150, 32);
RenderWindow window(mode, "SFML Window", Style::Close, settings);
window.SetFramerateLimit(60);
while (window.IsOpened() && running) {
window.Clear();
//listen for events
Event event;
while (window.GetEvent(event)) {
// a key is pressed
if (event.Type == Event::KeyPressed) {
} else if (event.Type == Event::Closed) {
cout << "closing" << endl;
}
}
window.Display();
}
cout << "Exiting..." << endl;
return EXIT_SUCCESS;
}
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::window_opened??)
//display titlebar here
}