本文整理汇总了C++中sf::RenderWindow类的典型用法代码示例。如果您正苦于以下问题:C++ RenderWindow类的具体用法?C++ RenderWindow怎么用?C++ RenderWindow使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RenderWindow类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
//Player rendering
void Player::draw(sf::RenderWindow& window, sf::View& view, Level level, string move) {
//Player control scheme
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || move == "up") {
//Grounded check
if (grounded) {
//Jump
velocity.y = -20;
position.y += 0.5;
grounded = false;
}
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || move == "left") {
//Move player left
velocity.x = -7;
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || move == "right") {
//Move player right
velocity.x = 7;
}
//Add force of gravity to player velocity
velocity.y += 0.8;
//Position at player center
int centerX = position.x - (size / 2);
int centerY = position.y - (size / 2);
//Dimensions
int halfSize = size / 2;
float skin = 2;
//Nearest tiles for preforming collision checks
Tile currentTile = level.getTileFromWorld(sf::Vector2f(centerX, centerY));
Tile below = level.getTileFromWorld(sf::Vector2f(centerX, centerY + (currentTile.size / 2) + velocity.y));
Tile right = level.getTileFromWorld(sf::Vector2f(centerX + skin + (currentTile.size / 2), centerY));
Tile top = level.getTileFromWorld(sf::Vector2f(centerX, centerY - skin - (currentTile.size / 2)));
Tile left = level.getTileFromWorld(sf::Vector2f(centerX - skin - (currentTile.size / 2), centerY));
//Check bottom collision
if (below.type != 0 && velocity.y > 0) {
grounded = true;
velocity.y = 0;
}
else {
grounded = false;
}
//Check top collision
if (top.type != 0 && velocity.y < 0) velocity.y = 0;
//Check left collision
if (left.type != 0 && velocity.x < 0) velocity.x = 0;
//Check right collision
if (right.type != 0 && velocity.x > 0) velocity.x = 0;
//Update player position
position.y += velocity.y;
position.x += velocity.x;
//Update position tracking
lastX = position.x;
//Centered camera
view.setCenter(position);
//Reset x velocity to prevent momentum build up
velocity.x = 0;
//Render player
shape.setPosition(position);
window.draw(shape);
};
示例2: getEvent
void getEvent(sf::Event& event, sf::RenderWindow& window, Input& in)
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
switch (event.key.code)
{
case sf::Keyboard::W: in.W = true; break;
case sf::Keyboard::A: in.A = true; break;
case sf::Keyboard::S: in.S = true; break;
case sf::Keyboard::D: in.D = true; break;
case sf::Keyboard::Up: in.W = true; break;
case sf::Keyboard::Left: in.A = true; break;
case sf::Keyboard::Down: in.S = true; break;
case sf::Keyboard::Right: in.D = true; break;
case sf::Keyboard::I: in.record = true; break;
case sf::Keyboard::O: in.edit = true; break;
case sf::Keyboard::P: in.predict = true; break;
case sf::Keyboard::Space: in.reset = true; break;
case sf::Keyboard::Num0: in.action = 0; break;
case sf::Keyboard::Num1: in.action = 1; break;
case sf::Keyboard::Num2: in.action = 2; break;
case sf::Keyboard::Num3: in.action = 3; break;
case sf::Keyboard::Num4: in.action = 4; break;
case sf::Keyboard::Num5: in.action = 5; break;
case sf::Keyboard::Num6: in.action = 6; break;
case sf::Keyboard::Num7: in.action = 7; break;
case sf::Keyboard::Num8: in.action = 8; break;
case sf::Keyboard::Num9: in.action = 9; break;
case sf::Keyboard::Numpad0: in.action = 10; break;
case sf::Keyboard::Numpad1: in.action = 11; break;
case sf::Keyboard::Numpad2: in.action = 12; break;
case sf::Keyboard::Numpad3: in.action = 13; break;
case sf::Keyboard::Numpad4: in.action = 14; break;
case sf::Keyboard::Numpad5: in.action = 15; break;
case sf::Keyboard::Numpad6: in.action = 16; break;
case sf::Keyboard::Numpad7: in.action = 17; break;
case sf::Keyboard::Numpad8: in.action = 18; break;
case sf::Keyboard::Numpad9: in.action = 19; break;
case sf::Keyboard::X: in.zoom += 0.5f; break;
case sf::Keyboard::Z: in.zoom -= 0.5f; break;
case sf::Keyboard::F1: in.action = -2;
default:
break;
}
break;
case sf::Event::KeyReleased:
switch (event.key.code)
{
case sf::Keyboard::W: in.W = false; break;
case sf::Keyboard::A: in.A = false; break;
case sf::Keyboard::S: in.S = false; break;
case sf::Keyboard::D: in.D = false; break;
case sf::Keyboard::Up: in.W = false; break;
case sf::Keyboard::Left: in.A = false; break;
case sf::Keyboard::Down: in.S = false; break;
case sf::Keyboard::Right: in.D = false; break;
default:
break;
}
default:
break;
}
}
示例3: Draw
void ParentUI::Draw(sf::RenderWindow &window)
{
window.draw(*m_arrow);
window.draw(*m_indicator);
window.draw(*m_parent_ball);
}
示例4: draw
void Projectile::draw(sf::RenderWindow & window, float dt)
{
window.draw(*this->projectileBody);
}
示例5: render
void score::render(sf::RenderWindow &app)
{
app.draw(_text);
}
示例6: render
void Block::render(sf::RenderWindow& window){
window.draw(_block);
}
示例7: entity_draw
void entity_draw(const Entity& entity, sf::RenderWindow& renderWindow)
{
renderWindow.draw(entity.sprite);
}
示例8: wyswietl
void Button::wyswietl(sf::RenderWindow &okno)
{
okno.draw(przycisk);
okno.draw(sprajt);
okno.draw(napis);
}
示例9: renderBackground
void Map::renderBackground(sf::RenderWindow& window) const
{
window.Draw(*mBackground);
}
示例10: renderForeground
void Map::renderForeground(sf::RenderWindow& window) const
{
window.Draw(*mForeground);
}
示例11: render
void SplashScreen::render(const sf::Time & /*dt*/, sf::RenderWindow &window)
{
window.draw(text);
}
示例12: render
void game::render(sf::RenderWindow &window)
{
window.display();
}
示例13: Render
void UnlockPew::Render(sf::RenderWindow &window){
if (m_active)
window.draw(pewDropSprite);
}
示例14: manageEvents
void Game::manageEvents(sf::RenderWindow &window, Character &player, TileMap map)
{
sf::Event event;
while (window.pollEvent(event))
{
// Close window : exit
if (event.type == Event::Closed)
{
window.close();
deleteAllMobs();
}
// Escape pressed : exit
else if (Keyboard::isKeyPressed(Keyboard::Escape))
{
window.close();
deleteAllMobs();
}
//Right arrow : move player right
else if (Keyboard::isKeyPressed(Keyboard::Right))
{
player.getAnimatedWalk().y=48*2;
player.collisionWithTileManager(map);
player.moveRight();
player.canMove();
}
//Left arrow : move player left
else if (Keyboard::isKeyPressed(Keyboard::Left))
{
player.getAnimatedWalk().y=48;
player.collisionWithTileManager(map);
player.moveLeft();
player.canMove();
}
//Up arrow : move player up
else if (Keyboard::isKeyPressed(Keyboard::Up))
{
player.getAnimatedWalk().y=48*3;
player.collisionWithTileManager(map);
player.moveUp();
player.canMove();
}
//Down arrow : move player down
else if (Keyboard::isKeyPressed(Keyboard::Down))
{
player.getAnimatedWalk().y=0;
player.collisionWithTileManager(map);
player.moveDown();
player.canMove();
}
if(Keyboard::isKeyPressed(Keyboard::Right)||Keyboard::isKeyPressed(Keyboard::Left) || //So walk animation only occur
Keyboard::isKeyPressed(Keyboard::Up) ||Keyboard::isKeyPressed(Keyboard::Down)) //when pler moved
{
//Animates the plaer's movements
player.getAnimatedWalk().x += 47;
if(player.getAnimatedWalk().x>=47*2)
player.getAnimatedWalk().x=0;
player.getSprite().setTextureRect(IntRect(player.getAnimatedWalk().x,player.getAnimatedWalk().y,47,47));
}
}
}
示例15: render
void SnakeNode::render(sf::RenderWindow& window)
{
window.draw(shape_);
}