本文整理汇总了C++中sf::View::getCenter方法的典型用法代码示例。如果您正苦于以下问题:C++ View::getCenter方法的具体用法?C++ View::getCenter怎么用?C++ View::getCenter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::View
的用法示例。
在下文中一共展示了View::getCenter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
void GameCompleteScreen::setup(sf::View view
, int sheepHerded)
{
mBackground.setPosition(view.getCenter());
sf::Vector2f textPos(view.getCenter());
float fontSize = mTitleText.getCharacterSize();
textPos.y -= fontSize;
mTitleText.setPosition(textPos);
textPos.y += fontSize;
mSheepStatText.setString("Sheep Herded " + std::to_string(sheepHerded));
sf::FloatRect bounds = mSheepStatText.getLocalBounds();
mSheepStatText.setOrigin(bounds.width / 2.f
, 0.f);
fontSize = mSheepStatText.getCharacterSize();
mSheepStatText.setPosition(textPos);
textPos.y += fontSize;
int inc = mMenuText.at(0).getCharacterSize();
textPos.y += inc;
for(sf::Text& text : mMenuText)
{
text.setPosition(textPos);
textPos.y += inc;
}
}
示例2: Drawbackground
void Map::Drawbackground(sf::View& ViewRef, E_Ground Ground)
{
int MinX, MaxX, MinY, MaxY;
if (WCR.inMapMaker)
{
MinX = (int)((WCR.MMPtr->MapMakrView.getCenter().x - (WCR.MMPtr->MapMakrView.getSize().x / 2)) / CellSize);
MaxX = (int)((WCR.MMPtr->MapMakrView.getCenter().x + (WCR.MMPtr->MapMakrView.getSize().x / 2)) / CellSize);
MinY = (int)((WCR.MMPtr->MapMakrView.getCenter().y - (WCR.MMPtr->MapMakrView.getSize().y / 2)) / CellSize);
MaxY = (int)((WCR.MMPtr->MapMakrView.getCenter().y + (WCR.MMPtr->MapMakrView.getSize().y / 2)) / CellSize);
}
else
{
MinX = (int)((ViewRef.getCenter().x - ViewRef.getSize().x / 2) / CellSize);
MaxX = (int)((ViewRef.getCenter().x + ViewRef.getSize().x / 2) / CellSize);
MinY = (int)((ViewRef.getCenter().y - ViewRef.getSize().y / 2) / CellSize);
MaxY = (int)((ViewRef.getCenter().y + ViewRef.getSize().y / 2) / CellSize);
}
WCR.LimitVariable(0, MapWidth - 1, MinX);
WCR.LimitVariable(0, MapWidth - 1, MaxX);
WCR.LimitVariable(0, MapHeight - 1, MinY);
WCR.LimitVariable(0, MapHeight - 1, MaxY);
for (int LID = 0; LID < BackgroundMatrix.size(); LID++)
{
if (WCR.MMPtr->OnlyShowThisLayer->IsActive() && WCR.inMapMaker && OrderedBackgroundLayers[LID] != WCR.MMPtr->curTileLayer)
continue;//Skip, not the layer we want.
int BL_ = BackgroundLayers[OrderedBackgroundLayers[LID]];
if (Ground == E_vForeground)
{
if (BL_ >= 0)
continue;//Not up to yet
}
else if (Ground == E_vMiddleground)
{
if (BL_ < 0)
break;//Gone past
if (BL_ != 0)
continue;//Go till found.
}
else if (Ground == E_vBackground)
{
if (BL_ < 1)
break;//Gone past
}
BL_ = OrderedBackgroundLayers[LID];
for (int i = MinX; i <= MaxX; i++)
for (int ii = MinY; ii <= MaxY; ii++)
{
if (BackgroundMatrix[BL_][i][ii].tileID != -1)//Not empty space.
{
WCR.MMPtr->TileSets[BackgroundMatrix[BL_][i][ii].tileSetID].Tiles[BackgroundMatrix[BL_][i][ii].tileID].setPosition(i * CellSize, ii * CellSize);
WCR.RenderRef.draw(WCR.MMPtr->TileSets[BackgroundMatrix[BL_][i][ii].tileSetID].Tiles[BackgroundMatrix[BL_][i][ii].tileID]);
}
}
}
}
示例3: isInsideView
inline bool isInsideView(const sf::View& targetView, const sf::FloatRect& boundingBox)
{
sf::FloatRect view(targetView.getCenter().x - targetView.getSize().x / 2.f,
targetView.getCenter().y - targetView.getSize().y / 2.f,
targetView.getSize().x,
targetView.getSize().y);
view.left -= VIEW_MARGIN;
view.top -= VIEW_MARGIN;
view.width += 2 * VIEW_MARGIN;
view.height += 2 * VIEW_MARGIN;
return view.intersects(boundingBox);
}
示例4: drawInViewSprites
void drawInViewSprites(sf::RenderWindow &window, sf::View &view,gameMap &map, std::vector< std::vector < sf::Sprite > > &sprites )
{
int leftX = floor((view.getCenter().x - view.getSize().x/2)/(map.getTile(0).getTileDims().x));
int rightX = ceil((view.getCenter().x + view.getSize().x/2)/(map.getTile(0).getTileDims().x));
int upY = floor((view.getCenter().y - view.getSize().y/2)/(map.getTile(0).getTileDims().y));
int downY = ceil((view.getCenter().y + view.getSize().y/2)/(map.getTile(0).getTileDims().y));
for(int y = upY; y<downY; y++)
{
for(int x = leftX; x<rightX; x++)
{
window.draw(sprites[y][x]);
}
}
}
示例5: BonusesPanelUpdate
void BonusesPanelUpdate(BonusesPanel& panel, sf::View view) {
float view_top = view.getCenter().y - view.getSize().y / 2.f;
float view_left = view.getCenter().x - view.getSize().x / 2.f;
panel.sprite.setPosition(view_left + PanelXPos, view_top + PanelYPos);
sf::FloatRect panel_box = panel.sprite.getGlobalBounds();
float cell_x = panel_box.left + PanelLeftBorderWidth;
float cell_y = panel_box.top + PanelTopBorderHeight;
float delimeter = 0;
for (size_t i = 0; i < panel.items->size(); i++) {
if (i != 0) {
delimeter = CellDelimeterHeight;
}
panel.items[0][i]->visual->sprite.setPosition(cell_x, cell_y + (CellHeight * i) + delimeter);
}
}
示例6: update
void Interface::update(sf::View v)
{
//Positions the text relative to the view:
_text[CLOCK].setPosition(
((v.getCenter().x - (v.getSize().x / 2)) + 5), //X
((v.getCenter().y - (v.getSize().y / 2)) + 5)); //Y
_text[CLOCK_BESTTIME].setPosition(
(_text[CLOCK].getPosition().x), //X
(_text[CLOCK].getPosition().y + (_text[CLOCK].getGlobalBounds().height + 2))); //Y
_text[FPS].setPosition(
((v.getCenter().x + (v.getSize().x / 2)) - (_text[FPS].getGlobalBounds().width + 5)), //X
((v.getCenter().y + (v.getSize().y / 2)) - (_text[FPS].getGlobalBounds().height + 5))); //Y
}
示例7: Update
void EffectsHandler::Update(float elapsed, sf::View &view, sf::RenderWindow &rw)
{
if (effectsList.empty())
{
return;
}
for (std::list<Effect>::iterator it = effectsList.begin(); it != effectsList.end(); it++)
{
switch (*it)
{
case ZoomIn:
if (view.getSize().x > rw.getSize().x/2)
{
view.setSize(view.getSize().x-(ZOOM_SPEED_X*elapsed), view.getSize().y-(ZOOM_SPEED_Y*elapsed));
view.setCenter(view.getCenter().x, view.getCenter().y-(ZOOM_POS_ABOVE_MIDDLE*elapsed));
}
else effectsList.erase(it++);
break;
case ZoomOut:
if (view.getSize().x <= rw.getDefaultView().getSize().x &&
view.getSize().y <= rw.getDefaultView().getSize().y) //seems silly to take &window just for getdefaultview.
{
view.setSize(view.getSize().x+(ZOOM_SPEED_X*elapsed), view.getSize().y+(ZOOM_SPEED_Y*elapsed));
view.setCenter(view.getCenter().x, view.getCenter().y+(ZOOM_POS_ABOVE_MIDDLE*elapsed));
}
else
{
effectsList.erase(it++);
view = rw.getDefaultView();
}
break;
case Pause:
totalelapsed += elapsed;
if (totalelapsed > 1.0f)
{
effectsList.erase(it++);
totalelapsed = 0;
}
break;
default:
break;
}
}
}
示例8: DrawTheMinimap
void Minimap::DrawTheMinimap(sf::RenderWindow& window, Game& game, sf::View view)
{
if (ShouldBeUpdated)
{
UpdateTheMinimap(game.map);
ShouldBeUpdated = false;
}
MinimapSprite.setPosition(sf::Vector2f(window.getSize().x - 200.f, 50.f));
window.draw(MinimapSprite);
MinimapBackground.setPosition(sf::Vector2f(window.getSize().x - 200.f, 50.f));
window.draw(MinimapBackground);
for (int j = 0; j < game.MOBs.size(); j++)
{
AllyMobSprite.setPosition(sf::Vector2f(game.MOBs[j]->position.x * MINIMAP_WIDTH / MAP_DIM / TEX_DIM + window.getSize().x - 200.f - 4, game.MOBs[j]->position.y * MINIMAP_WIDTH / MAP_DIM / TEX_DIM + 50.f));
window.draw(AllyMobSprite);
}
for (int j = 0; j < game.structures.size(); j++)
{
AllyPlantSprite.setPosition(sf::Vector2f(game.structures[j].position.x * MINIMAP_WIDTH / MAP_DIM + window.getSize().x - 200.f - 4, game.structures[j].position.y * MINIMAP_WIDTH / MAP_DIM + 50.f));
window.draw(AllyPlantSprite);
}
sf::Vector2f ViewSize = view.getSize();
sf::Vector2f ViewCornerPosition = view.getCenter() - ViewSize / 2.0f;
MinimapFOVIndicator.setPosition(ViewCornerPosition.x * MINIMAP_WIDTH / MAP_DIM / TEX_DIM + window.getSize().x - 200.f, ViewCornerPosition.y * MINIMAP_WIDTH / MAP_DIM / TEX_DIM + 50.f);
MinimapFOVIndicator.setSize(sf::Vector2f(ViewSize.x * MINIMAP_WIDTH / MAP_DIM / TEX_DIM, ViewSize.y * MINIMAP_WIDTH / MAP_DIM / TEX_DIM));
window.draw(MinimapFOVIndicator);
}
示例9: render
/* ----------------------------------------------------------------------
* Author: Julian
* Date: 25 March 2014
* Description: Renders the light manager
* ----------------------------------------------------------------------
*/
void LightManager::render(const sf::View& camera)
{
// Set the view of the camera
sf::Vector2f cameraPos(camera.getCenter() - sf::Vector2f(context.window->getSize() / 2u));
context.window->setView(camera);
// Clear the window to see light only
//context.window->clear(sf::Color::White);
// Clear the light texture
lightTexture.clear();
// Render all the lights
for(auto&& light : lightList)
light.render(camera, lightTexture);
// Render the dusk color over the light texture
sf::RectangleShape shape(sf::Vector2f(context.window->getSize()));
shape.setFillColor(duskColor);
lightTexture.draw(shape);
// Render the light texture on the rest of the window with BlendMultiply!
lightTexture.display();
sf::Sprite sprite(lightTexture.getTexture());
sprite.setPosition(cameraPos);
context.window->draw(sprite, sf::BlendMultiply);
}
示例10: rysuj_tekst
void rysuj_tekst( sf::RenderWindow & okno, sf::String _tresc, float x, float y )
{
double kamera_xHud = kamera.getCenter().x - kamera.getSize().x/2;
double kamera_yHud = kamera.getCenter().y - kamera.getSize().y/2;
tekst.setString( _tresc );
tekst.setPosition( kamera_xHud + x, kamera_yHud + y );
okno.draw( tekst );
}
示例11: set_up
void set_up(sf::RenderWindow& window, sf::View& view, sf::Text& winner, std::list<Cycle*>& player)
{
sf::Vector2u size = window.getSize();
if (size.x * 3 < size.y * 4)
{
view.setSize(v2f(800, (800.f * size.y) / size.x));
window.setView(view);
}
else if (size.x * 3 > size.y * 4)
{
view.setSize(v2f((600.f * size.x) / size.y, 600.f));
window.setView(view);
}
for (auto p : player)
p->set_text_pos(view.getCenter());
winner.setPosition(view.getCenter());
}
示例12: setView
void Renderer::setView(sf::View const& view)
{
m_renderer->setView(view);
m_screenRect = m_renderer->getViewport(view);
auto center = view.getCenter();
m_screenRect.left = center.x - m_screenRect.width / 2.f;
m_screenRect.top = center.y - m_screenRect.height / 2.f;
}
示例13: getViewPosition
sf::Vector2f getViewPosition(sf::View& view)
{
sf::Vector2f center = view.getCenter();
sf::Vector2f half = view.getSize() / 2.0f;
return center - half;
}
示例14: aktualizuj_hud
void aktualizuj_hud()
{
aktualizuj_kamere();
double kamera_xHud = kamera.getCenter().x - kamera.getSize().x/2;
double kamera_yHud = kamera.getCenter().y - kamera.getSize().y/2;
ustaw_pozycjePaskaHp( kamera_xHud+10 , kamera_yHud + 5 );
ustaw_pozycjePaskaBonusu( kamera_xHud+30 , kamera_yHud + 440 );
aktualizuj_timer( 1 );
}
示例15: logic
void Level::logic(sf::View& camera, unsigned int delta)
{
// Perform actions.
ActionInterface::logic(*this);
// Remove all dead entities.
for(list<Entity*>::iterator it = mDeadEntities.begin(); it != mDeadEntities.end(); it++)
mRemoveEntity(*it);
mDeadEntities.clear();
// Perform all entity logic.
for(list<Entity*>::iterator it = mEntities.begin(); it != mEntities.end(); it++)
(*it)->logic(*this, delta);
// If all items have been picked up, display a floating text and give a bonus.
if(mPickups.empty() && !mPickupAward)
{
addFloatingText("Level Cleared!", mPlayer.getPosition(), sf::Color::Yellow, 30);
distributeChangeScore(250);
mPickupAward = true;
}
// Perform floating text logic if the interval is passed.
if(mFloatingTextTimer.getTime() >= FLOATINGTEXT_TIMER_INTERVAL)
{
list<list<sf::Text>::iterator > removeList;
for(list<sf::Text>::iterator it = mFloatingTexts.begin(); it != mFloatingTexts.end(); ++it)
{
it->move(0, -FLOATINGTEXT_MOVE_STEP);
sf::Color c = it->getColor();
it->setColor(sf::Color(c.r, c.g, c.b, c.a - 3));
if(it->getColor().a == 0)
removeList.push_back(it);
}
for(list<list<sf::Text>::iterator >::iterator it = removeList.begin(); it != removeList.end(); ++it)
mFloatingTexts.erase(*it);
mFloatingTextTimer.start();
}
// Center the player on the screen.
camera.setCenter(mPlayer.getX() + (mPlayer.getWidth() / 2), mPlayer.getY() + (mPlayer.getHeight() / 2));
// Make sure that the camera doesn't go out of bounds.
sf::Vector2f center = camera.getCenter(),
half(camera.getSize().x / 2, camera.getSize().y / 2);
if(center.x - half.x < 0)
center.x = half.x;
if(center.x + half.x > mMap.getWidth())
center.x = mMap.getWidth() - half.x;
if(center.y - half.y < 0)
center.y = half.y;
if(center.y + half.y > mMap.getHeight())
center.y = mMap.getHeight() - half.y;
camera.setCenter(center);
}