本文整理汇总了C++中sf::RenderWindow::create方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderWindow::create方法的具体用法?C++ RenderWindow::create怎么用?C++ RenderWindow::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::RenderWindow
的用法示例。
在下文中一共展示了RenderWindow::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WindowInterface
void RenderState::WindowInterface(sel::State &p_lua_state, sf::RenderWindow &p_window)
{
auto lua_interface = p_lua_state["interface"];
lua_interface["createWindow"] = [&p_window] (int p_w, int p_h, int p_bpp, int p_fps, const std::string &p_title) -> void
{
//Check for negative values - no support for unsigned types in Selene
if(p_w < 0 || p_h < 0 || p_bpp < 0 || p_fps < 0)
throw std::runtime_error("Invalid video mode requested");
p_window.create(sf::VideoMode(p_w, p_h, p_bpp), p_title, sf::Style::None);
p_window.setFramerateLimit(p_fps);
p_window.setKeyRepeatEnabled(false);
return;
};
lua_interface["closeWindow"] = [&p_window] () -> void
{
p_window.close();
return;
};
lua_interface["resizeWindow"] = [&p_window] (int p_w, int p_h) -> void
{
//Check for negative values - no support for unsigned types in Selene
if(p_w < 0 || p_h < 0)
throw std::runtime_error("Invalid video mode requested");
p_window.setSize(sf::Vector2u(p_w, p_h));
return;
};
return;
}
示例2: main
int main(){
window.create(sf::VideoMode((unsigned int)windowWidth,(unsigned int)windowHeight),"MyWindow");
window.setFramerateLimit(60);
Setup();
running=true;
while(running){
while(window.pollEvent(event)){
if(event.type==sf::Event::Closed)
running=false;
else if(event.type==sf::Event::Resized)
ReshapeWindow((float)event.size.width,(float)event.size.height);
}
if (currentState == MAIN)
{
cmain.HandleKeyboard();
cmain.mouseControl();
}
else if (currentState == GAME)
{
cgame.HandleKeyboard();
handleKeyboard();
}
Display();
window.display();
}
return 0;
}
示例3: handleEvents
void StateBasedGame::handleEvents(sf::RenderWindow& container)
{
sf::Event event;
while (container.pollEvent(event))
{
if (event.type == sf::Event::Closed)
container.close();
if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Escape)
container.close();
if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::F11)
{
if(!winState.fullscreen)
{
container.create(winState.mode, winState.title, sf::Style::Fullscreen, winState.settings);
container.setVerticalSyncEnabled(winState.vSync);
container.setMouseCursorVisible(winState.cursor);
}
else
{
container.create(winState.mode, winState.title, sf::Style::Default, winState.settings);
container.setVerticalSyncEnabled(winState.vSync);
container.setMouseCursorVisible(winState.cursor);
}
winState.fullscreen = !winState.fullscreen;
}
#ifdef DEBUG
if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::F12)
{
Debug::OVERLAY_ON = !Debug::OVERLAY_ON;
}
#endif
if(!enterTransition && !leaveTransition && currentState->isInitialized())
{
currentState->handleEvents(event, *this);
}
}
}
示例4: toggleFullscreen
void toggleFullscreen() {
if (!bfullscreen)
{
screenW = VideoMode::getDesktopMode().width;
screenH = VideoMode::getDesktopMode().height;
}
else
{
screenW = 800;
screenH = 600;
}
mainWindow.create(sf::VideoMode(screenW, screenH),"SBRTS");
theMap.setViewSize(screenW, screenH);
debug("Switching screen to %d:%d",screenW,screenH);
bfullscreen = !bfullscreen;
}
示例5: main
int main(int argc, char** argv) {
srand((unsigned)time(nullptr));
window.create(sf::VideoMode(800, 600), "sfml",
sf::Style::Titlebar || sf::Style::Close);
window.setFramerateLimit(60);
window.setMouseCursorVisible(false);
sf::Listener::setPosition(400, 300, -400);
font.init();
walls.init();
player.init();
stars.resize(100);
sort(stars.begin(), stars.end(), [](const Star& a, const Star& b) {
return a.getSpeed() < b.getSpeed();
});
while (window.isOpen()) {
sf::Event e;
while (window.pollEvent(e)) {
switch (e.type) {
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
if (e.key.code == sf::Keyboard::Escape) window.close();
break;
default:
break;
}
}
window.clear();
update();
draw();
window.display();
}
return 0;
}
示例6: recreateWindow
inline void recreateWindow()
{
if(renderWindow.isOpen()) renderWindow.close();
renderWindow.create({width, height}, title,
fullscreen ? sf::Style::Fullscreen : sf::Style::Default,
sf::ContextSettings{0, 0, antialiasingLevel, 0, 0});
renderWindow.setSize(Vec2u(width * pixelMult, height * pixelMult));
renderWindow.setVerticalSyncEnabled(vsync);
renderWindow.setFramerateLimit(fpsLimited ? maxFPS : 0);
inputState.reset();
mustRecreate = false;
onRecreation();
}
示例7: main
int main()
{
window.create(sf::VideoMode(800, 600), "Breakfree");
window.setVerticalSyncEnabled(true);
//, sf::Style::Close|sf::Style::Titlebar);
if (!font.loadFromFile("Nirmala.ttf"))
return EXIT_FAILURE;
Levels lv;
Paddle pad;
InputManager input;
while (window.isOpen())
{
switch (level)
{
case 0:
lv.loadLv0();
break;
}
while (playing)
{
input.ExecuteEvents(window);
pad.Update();
window.clear(); // ------draw graphics here-------
sf::Text text("Score: " + std::to_string(score), font, 20);
text.setPosition(660, 220);
window.draw(text);
lv.Draw(window);
window.draw(pad.sprite);
window.draw(pad.ball);
window.display(); // -----------------------
}
}
return 0;
}
示例8: main
int main()
{
using namespace sf;
Color bg = randCol();
bool run = true;
unsigned score = 0;
VideoMode v = VideoMode::getDesktopMode();
v.width = 1;
v.height = 1;
w1.create(v, "Score: 0", Style::None);
while (run)
{
Event event;
while (w1.pollEvent(event))
{
switch (event.type)
{
case Event::Closed:
run = false;
break;
case Event::MouseButtonReleased:
{
std::stringstream scoreStream;
scoreStream << "Score: " << ++score;
w1.setTitle(scoreStream.str());
w1.setPosition(randPos());
bg = randCol();
break;
}
default:
break;
}
}
w1.clear(bg);
w1.display();
}
w1.close();
}
示例9: Start
void Game::Start() {
if (_gameState != Uninitialized)
return;
_mainWindow.create(sf::VideoMode(1280, 720), "BIT GAME");
_mainWindow.setIcon(BitGameIcon.width, BitGameIcon.height, BitGameIcon.pixel_data);
//_p1.load("Images/Player.png");
_p1.setPosition(1280/2, 720/2);
_p1.setOrigin(25, 45);
_p1.setFillColor(sf::Color(0,0,255,255));
_p1.setRadius(10.f);
_gameState = Game::ShowingSplash;
while (!IsExiting()) {
GameLoop();
}
_mainWindow.close();
}
示例10: setOptions
void Setup::setOptions( sf::RenderWindow& window)
{
//sf::ContextSettings settings
window.create(sf::VideoMode(800, 608), "MASim", sf::Style::Default, sf::ContextSettings(32));
window.setVerticalSyncEnabled(true);
window.setFramerateLimit(60);
/* // Load an OpenGL texture.
// We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function),
// but here we want more control on it (generate mipmaps, ...) so we create a new one from an image
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glClearDepth(1.f);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);*/
}
示例11: main
// Program entry point
int main(int argc, char ** argv) {
titleImg.loadFromFile("assets/title.png");
sf::SoundBuffer sb;
sb.loadFromFile("assets/avalanche.ogg");
boulderSound.setBuffer(sb);
boulderSound.setLoop(true);
boulderSound.play();
sf::SoundBuffer sb2;
sb2.loadFromFile("assets/death.ogg");
fallingSound.setBuffer(sb2);
fallingSound.setRelativeToListener(true);
sf::SoundBuffer sb3;
sb3.loadFromFile("assets/jump.wav");
jumpingSound.setBuffer(sb3);
jumpingSound.setRelativeToListener(true);
sf::SoundBuffer sb4;
sb4.loadFromFile("assets/POL-flash-run-short.wav");
musicSound.setBuffer(sb4);
musicSound.setRelativeToListener(true);
musicSound.setVolume(15.f);
musicSound.setLoop(true);
musicSound.play();
sf::SoundBuffer sb5;
sb5.loadFromFile("assets/footsteps.ogg");
feetSound.setRelativeToListener(true);
feetSound.setBuffer(sb5);
feetSound.setLoop(true);
feetSound.setVolume(50);
feetSound.play();
sf::SoundBuffer sb6;
sb6.loadFromFile("assets/bump.ogg");
bumpSound.setRelativeToListener(true);
bumpSound.setBuffer(sb6);
bumpSound.setVolume(40);
sf::SoundBuffer sb7;
sb7.loadFromFile("assets/gem.ogg");
gemSound.setRelativeToListener(true);
gemSound.setBuffer(sb7);
gemSound.setVolume(60);
sf::SoundBuffer sb8;
sb8.loadFromFile("assets/Powerup3.wav");
powerSound.setRelativeToListener(true);
powerSound.setBuffer(sb8);
powerSound.setVolume(80);
sf::SoundBuffer sb9;
sb9.loadFromFile("assets/alert.ogg");
alertSound.setRelativeToListener(true);
alertSound.setBuffer(sb9);
//powerSound.setVolume(80);
// Create the SFML window
window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "A Bolder Escape");
while (window.isOpen()) {
events();
if (!menu) logic();
render();
}
return 0;
}
示例12: ventanaPrincipal
void Administrador::ventanaPrincipal()
{
sf::Texture text_fondo, txt_lateral, txt_nuevaRuta, text_consultar, text_eliminar, text_salir;
sf::Sprite back_fondo, back_lateral, back_nuevaRuta, back_consultar, back_eliminar, back_salir;
sf::Texture txt_puntos[23];
sf::Sprite back_puntos[23];
window.create(sf::VideoMode(1280,680),"Transportes Inter-Urbanos");
window.setPosition(sf::Vector2i(50,0));
text_fondo.loadFromFile("mapa.png");
back_fondo.setTexture(text_fondo);
txt_lateral.loadFromFile("barra_lateral.png");
back_lateral.setTexture(txt_lateral);
back_lateral.setPosition(1100,0);
txt_nuevaRuta.loadFromFile("botones/nueva_ruta.png");
back_nuevaRuta.setTexture(txt_nuevaRuta);
back_nuevaRuta.setPosition(1105,60);
text_consultar.loadFromFile("botones/consultar_ruta.png");
back_consultar.setTexture(text_consultar);
back_consultar.setPosition(1105,130);
text_eliminar.loadFromFile("botones/eliminar_ruta.png");
back_eliminar.setTexture(text_eliminar);
back_eliminar.setPosition(1105,200);
text_salir.loadFromFile("botones/btnSalir.png");
back_salir.setTexture(text_salir);
back_salir.setPosition(1105,270);
ruta->llenarPuntos();
ruta->setAdyacencias();
ruta->setCaminos();
ruta->setPesos();
ruta->rutasPosibles();
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
mouse = window.mapPixelToCoords(sf::Mouse::getPosition(window));
}
if(utility->clickSprite(back_nuevaRuta,mouse))
{
crearRuta();
}
if(utility->clickSprite(back_consultar,mouse))
{
ventanaConsultarCaminos();
}
if(utility->clickSprite(back_eliminar,mouse))
{
ventanaEliminar();
}
if(utility->clickSprite(back_salir,mouse))
{
window.close();
}
window.draw(back_fondo);
window.draw(back_lateral);
window.draw(back_nuevaRuta);
window.draw(back_consultar);
window.draw(back_eliminar);
window.draw(back_salir);
dibujarPuntos(txt_puntos, back_puntos);
drawLineas();
window.display();
}
}
示例13: main
int main() {
sf::ContextSettings settings;
settings.antialiasingLevel = 8; //smoother shapes
window.create(sf::VideoMode(800, 600), "AKB48 Ongaku Geimu (alpha) v0.4", sf::Style::Default, settings);
window.setVerticalSyncEnabled(true);
/*
window.setMouseCursorVisible(false); // Hide cursor
sf::View fixed = window.getView(); // Create a fixed view
// Load image and create sprite
sf::Texture mouseTexture;
mouseTexture.loadFromFile("cursors/mayuyu.png");
sf::Sprite mouseSprite(mouseTexture);
mouseSprite.rotate(-45);
*/
srand(time(NULL)); //seed random based on time
//load fonts
sf::Font gameFont;
if (!gameFont.loadFromFile("gothic.ttf")) {
//error
std::cout << "Cannot load font\n";
}
sf::Font japaneseFont;
if (!japaneseFont.loadFromFile("msmincho.ttc")) {
//error
std::cout << "Cannot load font\n";
}
//load background
sf::Texture backTexture;
if (!backTexture.loadFromFile("title_screen.png")) {
//error
}
backTexture.setSmooth(true);
backTexture.setRepeated(false);
sf::Sprite backSprite;
backSprite.setTexture(backTexture);
backSprite.setColor(sf::Color(255, 255, 255, 224)); //semi-transparent
//Load title text
sf::Text titleText;
titleText.setCharacterSize(50);
//load buttons
sf::RectangleShape startButton(sf::Vector2f(300,100));
startButton.setFillColor(sf::Color(200, 50, 5, 128));
startButton.setOutlineThickness(5);
startButton.setOutlineColor(sf::Color(200, 50, 5, 128));
startButton.setPosition(250, 250);
sf::RectangleShape createButton(sf::Vector2f(300, 100));
createButton.setFillColor(sf::Color(10, 150, 55, 192));
createButton.setOutlineThickness(5);
createButton.setOutlineColor(sf::Color(10, 150, 55, 192));
createButton.setPosition(250, 400);
//load button text
sf::Text startText;
startText.setCharacterSize(50);
sf::Text createText;
createText.setCharacterSize(40);
//load music player graphics
//music player black container
sf::RectangleShape musicBox(sf::Vector2f(311, 30));
musicBox.setFillColor(sf::Color(32, 32, 32, 224));
musicBox.setPosition(sf::Vector2f(484, 565));
//play button
sf::CircleShape playButton;
playButton.setPointCount(3);
playButton.setRotation(210);
playButton.setRadius(10);
playButton.setFillColor(sf::Color(224, 224, 224, 224));
playButton.setOutlineColor(sf::Color(128, 128, 128, 224));
playButton.setPosition(sf::Vector2f(498, 593));
//stop button
sf::CircleShape stopButton;
stopButton.setPointCount(4);
stopButton.setRadius(11);
stopButton.setRotation(45);
stopButton.setFillColor(sf::Color(224, 224, 224, 224));
stopButton.setOutlineColor(sf::Color(128, 128, 128, 224));
stopButton.setPosition(sf::Vector2f(523, 565));
//skip left button
sf::CircleShape skipLeftButton;
skipLeftButton.setPointCount(3);
skipLeftButton.setRotation(30);
skipLeftButton.setRadius(5);
skipLeftButton.setFillColor(sf::Color(224, 224, 224, 224));
skipLeftButton.setOutlineColor(sf::Color(128, 128, 128, 224));
//skip right button
sf::CircleShape skipRightButton;
skipRightButton.setPointCount(3);
skipRightButton.setRotation(210);
skipRightButton.setRadius(5);
skipRightButton.setFillColor(sf::Color(224, 224, 224, 224));
//.........这里部分代码省略.........
示例14: setWindowSettings
void setWindowSettings(const std::string &_p_name, uint16_t _p_width, uint16_t _p_height, bool _p_fullscreen)
{
m_window.create(sf::VideoMode(_p_width, _p_height), _p_name, _p_fullscreen ? sf::Style::Fullscreen : sf::Style::Close);
m_window.setVerticalSyncEnabled(true);
}
示例15: main
int main()
{
deltaTime = 0;
sfg::SFGUI sfgui;
// map sprite
sf::Texture map_texture;
sf::Sprite map_sprite;
map_texture.loadFromFile("resources/map.png");
map_sprite.setTexture(map_texture);
// window
window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32), "Runestone");
view.setSize(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT));
view.setCenter(sf::Vector2f(0, 0));
window.setView(view);
// timer
sf::Clock clock;
// thor actions
thor::Action quit(sf::Event::Closed);
thor::Action left(sf::Keyboard::A, thor::Action::Hold);
thor::Action right(sf::Keyboard::D, thor::Action::Hold);
thor::Action up(sf::Keyboard::W, thor::Action::Hold);
thor::Action down(sf::Keyboard::S, thor::Action::Hold);
thor::Action mouse_down(sf::Mouse::Left, thor::Action::PressOnce);
thor::Action mouse_up(sf::Mouse::Left, thor::Action::ReleaseOnce);
// thor action map
thor::ActionMap<std::string> action_map;
action_map["quit"] = quit;
action_map["left"] = left;
action_map["right"] = right;
action_map["up"] = up;
action_map["down"] = down;
action_map["mouse_down"] = mouse_down;
action_map["mouse_up"] = mouse_up;
thor::ActionMap<std::string>::CallbackSystem action_callbacks;
action_callbacks.connect("quit", &OnQuit);
action_callbacks.connect("left", &OnLeft);
action_callbacks.connect("right", &OnRight);
action_callbacks.connect("up", &OnUp);
action_callbacks.connect("down", &OnDown);
action_callbacks.connect("mouse_down", &OnMouseDown);
action_callbacks.connect("mouse_up", &OnMouseUp);
// thor particles
sf::Texture particleTexture;
particleTexture.loadFromFile("Media/particle.png");
emitter.setEmissionRate(100.0f);
emitter.setParticleLifetime(sf::seconds(1.0f));
particle_system.setTexture(particleTexture);
// sfgui
auto sfgui_window = sfg::Window::Create();
sfgui_window->SetTitle("Runestones: ");
auto rune_one = sfg::Button::Create("Rune One");
rune_one->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneOne));
rune_one->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked));
auto rune_two = sfg::Button::Create("Rune Two");
rune_two->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneTwo));
rune_two->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked));
auto rune_three = sfg::Button::Create("Rune Three");
rune_three->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneThree));
rune_three->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked));
auto rune_four = sfg::Button::Create("Rune Four");
rune_four->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneFour));
rune_four->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked));
auto hbox = sfg::Box::Create(sfg::Box::Orientation::HORIZONTAL, 4.0f);
hbox->Pack(rune_one);
hbox->Pack(rune_two);
hbox->Pack(rune_three);
hbox->Pack(rune_four);
sfgui_window->Add(hbox);
sfgui_window->SetStyle(!sfg::Window::Style::RESIZE);
sfgui_window->SetPosition(sf::Vector2f((WINDOW_WIDTH / 2.0f) -
(sfgui_window->GetAllocation().width / 2.0f), WINDOW_HEIGHT - sfgui_window->GetAllocation().height));
// tileset
sf::Texture tileTexture;
tileTexture.loadFromFile("resources/tiles.png");
rf::TileMap tileMap(4, 8);
tileMap.setTexture(tileTexture);
int layout[4][8] =
{
{-1, -1, -1, 1, 1, -1, -1, -1},
{1,1,1,1,1,1,1,1},
{-1,-1,1,1,1,1,-1,-1},
{1,1,1,1,1,1,1,1}
};
for (size_t i = 0; i < 4; i++)
{
for (size_t j = 0; j < 8; j++)
{
tileMap.setTile(layout[i][j], i, j);
}
}
//.........这里部分代码省略.........