本文整理汇总了C++中sf::View类的典型用法代码示例。如果您正苦于以下问题:C++ View类的具体用法?C++ View怎么用?C++ View使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了View类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setView_Scroll
void setView_Scroll(sf::View &view, Character &character, gameMap &map)
{
float height = view.getSize().y;
float width = view.getSize().x;
float maxW = map.getWidth()*(map.getTile(0).getTileDims().x);
float maxH = map.getHeight()*(map.getTile(0).getTileDims().y);
float newX = 0;
float newY = 0;
if(character.getPosition().x < width/2)
{
newX = width/2;
}else if(character.getPosition().x > maxW - width/2)
{
newX = maxW - width/2;
}else
{
newX = round(character.getPosition().x);
}
if(character.getPosition().y < height/2)
{
newY = height/2;
}else if(character.getPosition().y > maxH - height/2)
{
newY = maxH - height/2;
}else
{
newY = round(character.getPosition().y);
}
view.setCenter(newX, newY);
}
示例2: HandleView
void Game::HandleView(sf::View &view, sf::View &static_view, sf::RenderWindow &window){
if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
view.move(0, -16);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
view.move(-16, 0);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
view.move(0, 16);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
view.move(16, 0);
window.setView(static_view);
money_text.setString("Money: " + SSTR(values.Money()));
window.draw(money_text);
static bool help_toggled = true;
static bool key_released = true;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::H) and key_released == true){
help_toggled = !help_toggled;
key_released = false;
}else if(!sf::Keyboard::isKeyPressed(sf::Keyboard::H))
key_released = true;
if(help_toggled){
help_text.setString("building price: " + SSTR(values.BuildingPrice()) + "\nclaim & upgrade price = 10\nmoney cap = " + SSTR(values.MoneyCap()) + "\n\nc = claim\nr = build resource\nb = build bank\nu = improve\np = sell for 10\n\ntoggle help = h");
window.draw(help_text);
}
}
示例3: 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;
}
}
示例4: 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);
}
示例5: originalWidth
RuntimeCamera::RuntimeCamera(sf::View & view) :
originalWidth(view.getSize().x),
originalHeight(view.getSize().y),
angle(0),
zoomFactor(1)
{
sfmlView = view;
}
示例6: getViewPosition
sf::Vector2f getViewPosition(sf::View& view)
{
sf::Vector2f center = view.getCenter();
sf::Vector2f half = view.getSize() / 2.0f;
return center - half;
}
示例7: setView
void LightSystem::setView(const sf::View& view)
{
_renderTexture.create(view.getSize().x,view.getSize().y);
_buffer.create(view.getSize().x,view.getSize().y);
_sprite.setTexture(_renderTexture.getTexture(),true);
_bufferSprite.setTexture(_buffer.getTexture(),true);
}
示例8: 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]);
}
}
}
}
示例9: 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);
}
示例10: viewRect
sf::FloatRect viewRect(sf::View const& view)
{
sf::Vector2f const viewCenter(view.getCenter());
sf::Vector2f const viewSize(view.getSize());
sf::FloatRect const viewRect(
viewCenter.x - viewSize.x / 2,
viewCenter.y - viewSize.y / 2,
viewSize.x,
viewSize.y);
return viewRect;
}
示例11: getViewBounds
sf::FloatRect Helper::getViewBounds(const sf::View &view)
{
sf::FloatRect rt;
rt.left = view.getCenter().x - view.getSize().x/2;
rt.top = view.getCenter().y - view.getSize().y/2;
rt.width = view.getSize().x;
rt.height = view.getSize().y;
// std::cout << "View bounds" << rt.left << " " << rt.top << " " << rt.width << " " << rt.height << std::endl;
return rt;
}
示例12: 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);
}
示例13: main
int main(int argc, char** argv)
{
fcnt = 0;
speed = 0.5;
gen = 1;
evolution_rate = 10;
counter = 300;
bestavg = 0;
decline_counter = 0;
srand(time(0));
camera.setSize(800,600);
camera.setCenter(AREA_W/2,AREA_H/2);
sf::ContextSettings settings;
settings.antialiasingLevel = 8;
window = new sf::RenderWindow(sf::VideoMode(SCREEN_W,SCREEN_H),"Evolution 0.3",sf::Style::Default,settings);
window->setFramerateLimit(60);
window->setView(camera);
bg.setOutlineColor(sf::Color::Cyan);
bg.setOutlineThickness(4.f);
bg.setFillColor(sf::Color(51,153,153));
sf::CircleShape* tmp;
tmp = new sf::CircleShape(15.f,5);
tmp->setOutlineColor(sf::Color::Red);
tmp->setFillColor(sf::Color(75,75,75));
tmp->setOutlineThickness(2.f);
tmp->setOrigin(tmp->getLocalBounds().width/2,tmp->getLocalBounds().height/2);
fToken = tmp;
sf::Font font;
font.loadFromFile("revalia.ttf");
text = new sf::Text();
text->setFont(font);
text->setCharacterSize(15.f);
text->setColor(sf::Color::White);
vpop = new VectorPopulation();
vpop->setMutationScale(current_mutation_rate);
for(int i = 0; i<CREATURE_CAP; i++) {
creatures.push_back(std::shared_ptr<Creature>(new Creature(4,2,1,6)));
creatures.back()->setPos(sf::Vector2f(10 + rand() % (AREA_W-20), 10 + rand() % (AREA_H-20)));
creatures.back()->areaSize(AREA_W,AREA_H);
creatures.back()->setSpeed(3);
}
for(int i = 0; i<FOOD_CAP; i++) {
food.push_back(sf::Vector2f(20 + rand() % (AREA_W-40), 10 + rand() % (AREA_H-20)));
}
while(update()) {
render();
}
return 0;
}
示例14: 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);
}
}
示例15: 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
}