本文整理汇总了C++中sf::RenderWindow::GetFrameTime方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderWindow::GetFrameTime方法的具体用法?C++ RenderWindow::GetFrameTime怎么用?C++ RenderWindow::GetFrameTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::RenderWindow
的用法示例。
在下文中一共展示了RenderWindow::GetFrameTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void Creature::Update(sf::RenderWindow &app, sf::View &camera)
{
xSpeed += horizontal * app.GetFrameTime();
ySpeed += vertical * app.GetFrameTime();
xSpeed *= 1 - tan(friction*PI/2) * app.GetFrameTime();
ySpeed *= 1 - tan(friction*PI/2) * app.GetFrameTime();
move(xSpeed * app.GetFrameTime(), ySpeed * app.GetFrameTime());
}
示例2:
void df::Context::ExtractRenderWindowStatus(sf::RenderWindow const &renderWindow)
{
_ellapsedTime = renderWindow.GetFrameTime();
_frameRate = 1.f/_ellapsedTime;
_windowSize.Width = renderWindow.GetWidth();
_windowSize.Height = renderWindow.GetHeight();
}
示例3: draw
void Player::draw(sf::RenderWindow& window)
{
if (isAnimated)
{
//Anim has completed?
if(!saiyan.Update(window.GetFrameTime()))
{
isAnimated = false;
saiyan.Reset();
//Play song
Music::GetInstance().playRageMode();
}
//Find sprite center
float centerX = avatar.GetPosition().x + avatar.GetSize().x / 2;
float centerY = avatar.GetPosition().y + avatar.GetSize().y / 2;
float x = centerX - saiyanSprite.GetSize().x /2;
float y = centerY - saiyanSprite.GetSize().y /2;
saiyanSprite.SetPosition(x, y);
window.Draw(saiyanSprite);
}
else
{
window.Draw(avatar);
}
rageMeter = sf::Shape::Rectangle(0, 0, rage, 15, sf::Color::Red);
rageMeter.SetPosition(25,75);
window.Draw(rageMeterBox);
window.Draw(rageMeter);
window.Draw(rageStr);
}
示例4: update
void backgroundManager::update(sf::RenderWindow &Screen){
if(sprite.GetPosition().y+(sprite.GetSize().y/2)>=screenSize.y){
sprite.SetPosition(0,-screenSize.y);
}
sprite.Move(0,Screen.GetFrameTime()*scrollSpeed);
draw(Screen);
}
示例5: textDisplay
void Visual::textDisplay(sf::RenderWindow& mainWindow)
{
//draw text
sf::String text("", font, 15);
text.SetPosition(5, 5);
std::ostringstream sstream;
int fps = static_cast<int>(1 / mainWindow.GetFrameTime());
sstream << "FPS: ";
sstream << fps;
if (totalFPS > 4000000000 || frameCount > 700)
{
totalFPS = 0;
frameCount = 0;
}
if (fps >= 0)
totalFPS += fps;
frameCount++;
sstream << "\nAvg FPS: ";
sstream << totalFPS / frameCount;
text.SetText(sstream.str());
sstream.end;
text.SetColor(sf::Color::Green);
mainWindow.Draw(text);
}
示例6: Draw
void Player::Draw(sf::RenderWindow& W){
if(lives > 3)
lives = 3;
Anim->Animate(W.GetFrameTime());
Anim->SetPosition(left, up);
Anim->Draw(W);
}
示例7: playDeath
bool Player::playDeath(sf::RenderWindow& window)
{
window.Clear();
bool result = death.Update(window.GetFrameTime());
window.Draw(death_sprite);
return result;
}
示例8: evolue
// Actions joueur
void Player::evolue(sf::RenderWindow& app)
{
const sf::Input& input = app.GetInput();
m_frame = app.GetFrameTime();
// Déplacement à la souris
if(m_sprite.GetPosition().y > input.GetMouseY()-PLAYER_SIZE/2)
Move(Player::TOP);
else if(m_sprite.GetPosition().y < input.GetMouseY()-PLAYER_SIZE/2)
Move(Player::BOTTOM);
if(m_sprite.GetPosition().x > input.GetMouseX()-PLAYER_SIZE/2)
Move(Player::LEFT);
else if(m_sprite.GetPosition().x < input.GetMouseX()-PLAYER_SIZE/2)
Move(Player::RIGHT);
}
示例9: AddHelpText
void AddHelpText(sf::RenderWindow &App, sf::Font &f, GroupManager &gm)
{
sf::View v = App.GetView();
sf::Vector2f center = v.GetCenter(), half = v.GetHalfSize();
string s;
s = "Operations available:\n";
s += "Move: Left, Right, Up, Down\n";
s += "Speed: s (decrease), d (increase)\n";
s += "Step size: w (decrease), e (increase)\n";
s += "Zoom: z (in), x (out)\n";
s += "Steps mode: a (switch between modes)\n";
s += "Quit: Esc\n";
sf::String text(s, f, 12);
text.SetColor(sf::Color(128, 200, 40));
text.Move(center.x - half.x + half.x/20, center.y - half.y + half.y/20);
App.Draw(text);
ostringstream step_per_second_str;
step_per_second_str << "~" << step_per_second << "\n";
ostringstream step_time_str;
step_time_str << "~" << step_time << "\n";
ostringstream framerate_str;
framerate_str << 1.0/App.GetFrameTime() << "\n";
ostringstream step_size_str;
step_size_str << gm.GetStepSize() << "\n";
s = "Steps per second: ";
s += step_per_second_str.str() ;
s += "Step time: ";
s += step_time_str.str();
s += "Framerate: ";
s += framerate_str.str();
s += "Step size: ";
s += step_size_str.str();
s += "Steps mode: ";
switch (step_mode)
{
case SM_HARD_STEPS_CNT: s += "SM_HARD_STEPS_CNT\n"; break;
case SM_FREE_STEPS_CNT: s += "SM_FREE_STEPS_CNT\n"; break;
default: break;
}
sf::String inf(s.c_str(), f, 20);
inf.SetColor(sf::Color(230, 200, 180));
inf.Move(center.x - half.x + half.x/20, center.y + half.y - half.y/2);
App.Draw(inf);
}
示例10: Update
void Animation::Update(sf::RenderWindow &Window)
{
if(active)
frameCounter += (int)Window.GetFrameTime();
else
frameCounter = 0;
if (frameCounter >= switchFrame)
{
frameCounter = 0;
currentFrameX += getFrameWidth();
if(currentFrameX >= spriteImage.GetImage()->GetWidth())
currentFrameX = 0;
}
spriteImage.SetSubRect(sf::IntRect(currentFrameX, currentFrameY * getFrameHeight(), currentFrameX +getFrameWidth(), currentFrameY + getFrameHeight()));
spriteImage.SetPosition(x, y);
}
示例11: Update
void Paddle::Update(sf::RenderWindow& app)
{
float speed = 0;
// get player input
if(app.GetInput().IsKeyDown(sf::Key::Up))
{
if(Y > 0)
speed = -defaultSpeed;
}
if(app.GetInput().IsKeyDown(sf::Key::Down))
{
if(Y + H < screenHeight)
speed = defaultSpeed;
}
Y += speed * app.GetFrameTime();
SetPosition(X, Y);
}
示例12: Update
void Player::Update(sf::RenderWindow & App, class Physic & physic)
{
if(!m_inited)
Init(physic);
const sf::Input & _input = App.GetInput();
physic.GetPlayer(0)->vel = physic.GetPlayer(0)->body->GetLinearVelocity();
physic.GetPlayer(0)->rotation = physic.GetPlayer(0)->body->GetAngle();
if(_input.IsKeyDown(sf::Key::A)) { physic.GetPlayer(0)->rotation += -1.0f * App.GetFrameTime(); physic.GetPlayer(0)->body->SetTransform(physic.GetPlayer(0)->body->GetPosition(), physic.GetPlayer(0)->rotation); /*m_rotationDegree -= 3; m_rotation = 3; m_player.Rotate( (float)m_rotation );*/ } // turn LEFT
if(_input.IsKeyDown(sf::Key::D)) { physic.GetPlayer(0)->rotation += 1.0f * App.GetFrameTime(); physic.GetPlayer(0)->body->SetTransform(physic.GetPlayer(0)->body->GetPosition(), physic.GetPlayer(0)->rotation); /*m_rotationDegree += 3; m_rotation = -3; m_player.Rotate( (float)m_rotation );*/ } // turn RIGHT
if(_input.IsKeyDown(sf::Key::W)) { m_V += 2.00 ; }
if(_input.IsKeyDown(sf::Key::S)) { m_V -= 1.00 ; }
if(_input.IsKeyDown(sf::Key::Space)) { m_V = 0.0 ; }
physic.GetPlayer(0)->body->SetAngularVelocity(0.f);
/*
if(m_clock2.GetElapsedTime() > 1.0f)
{
if(_input.IsMouseButtonDown(sf::Mouse::Left))
{
Shoot(App);
m_reload = true;
m_clock2.Reset();
}
m_reload = false;
}
else
{
m_reload = true;
}
*/
// UpdateBullets(App);
// m_mousePozVec.x = _input.GetMouseX();
// m_mousePozVec.y = _input.GetMouseY();
m_mousePozVec = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());
m_xH = m_cannon.GetPosition().x - m_mousePozVec.x;
m_yH = m_cannon.GetPosition().y - m_mousePozVec.y;
m_cannonRotation =(float)(atan2(m_yH,m_xH) * 180.f / b2_pi + 180.f);
// if(physic.GetPlayer(0)->rotation > 359) physic.GetPlayer(0)->rotation = 0;
// if(physic.GetPlayer(0)->rotation < 0) physic.GetPlayer(0)->rotation = 359;
if( m_V > m_maxPlayerSpeed ) m_V = m_maxPlayerSpeed;
if( m_V < m_maxPlayerBackSpeed ) m_V = m_maxPlayerBackSpeed;
physic.GetPlayer(0)->vel.x = m_V * cos((b2_pi*(physic.GetPlayer(0)->rotation * RADTODEG ))/180.f);
physic.GetPlayer(0)->vel.y = m_V * sin((b2_pi*(physic.GetPlayer(0)->rotation * RADTODEG ))/180.f);
// if( m_disVec.x >= 1 || m_disVec.x <= - 1 ) { m_playerPozVec.x += int(m_disVec.x) * App.GetFrameTime(); m_disVec.x = m_disVec.x - int( m_disVec.x ); }
// if( m_disVec.y >= 1 || m_disVec.y <= - 1 ) { m_playerPozVec.y += int(m_disVec.y) * App.GetFrameTime(); m_disVec.y = m_disVec.y - int( m_disVec.y ); }
physic.GetPlayer(0)->body->SetLinearVelocity(physic.GetPlayer(0)->vel);
m_player.SetPosition( physic.GetPlayer(0)->GetPosition() );
m_player.SetRotation( -physic.GetPlayer(0)->rotation * RADTODEG );
m_cannon.SetPosition(m_player.GetPosition());
m_cannon.SetRotation(-m_cannonRotation);
/*
#pragma region DEBUG INFO
std::ostringstream bufor;
sf::String tdebug;
tdebug.SetFont(LoadContent::GetInstance()->m_font2);
tdebug.SetSize(20);
bufor << "\nFPS = " << _Framerate;
tdebug.SetText(bufor.str());
App.Draw(tdebug);
#pragma endregion
*/
App.Draw(m_player);
App.Draw(m_cannon);
}
示例13: Gravity
void Player::Gravity(sf::RenderWindow &app){
m_vely+=GameConfig::g_config["gravity"]/1000.f*app.GetFrameTime();
}
示例14: update
int GameScreen::update (sf::RenderWindow &app)
{
int nextScreen = myID;
float elapsedTime = app.GetFrameTime();
sf::Event event;
while (app.GetEvent(event)) // Boucle des évènements en attente
{
if (event.Type == sf::Event::Closed)
{
return EXIT;
}
else if(m_iHandler->testEvent(event, "Quit"))
{
return EXIT;
}
else if (event.Type == sf::Event::MouseMoved)
{
sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseMove.X, event.MouseMove.Y, &ConfigOptions::getView());
m_cursor.moveOnSquare(BoardAlignedSprite::toSquares(mouseCoords), false);
}
else if(m_iHandler->testEvent(event, "Up"))
{
sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(0, -1);
if(isValid(s))
m_cursor.moveOnSquare(s, false);
}
else if(m_iHandler->testEvent(event, "Left"))
{
sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(-1, 0);
if(isValid(s))
m_cursor.moveOnSquare(s, false);
}
else if(m_iHandler->testEvent(event, "Down"))
{
sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(0, 1);
if(isValid(s))
m_cursor.moveOnSquare(s, false);
}
else if(m_iHandler->testEvent(event, "Right"))
{
sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(1, 0);
if(isValid(s))
m_cursor.moveOnSquare(s, false);
}
else if(playerHasHand())
{
if(m_iHandler->testEvent(event, "Save"))
{
m_game.saveToFile(BACKUP_FILE);
}
else if(m_iHandler->testEvent(event, "Load"))
{
m_game.loadFromFile(BACKUP_FILE);
refreshAll();
}
else if (m_iHandler->testEvent(event, "LClick"))
{
sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, &ConfigOptions::getView());
sf::Vector2i s = BoardAlignedSprite::toSquares(mouseCoords);
if(isValid(s))
clickOn(s);
else if(!m_game.hasStarted())
{
PieceType type = m_placementUI.click(mouseCoords);
if(type == NB_PIECES) //end of turn
tryAndEndTurn();
else
m_selectedType = type;
}
}
if (m_iHandler->testEvent(event, "Choose"))
{
sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition());
if(isValid(s))
clickOn(s);
}
else if (m_iHandler->testEvent(event, "RClick"))
{
sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, &ConfigOptions::getView());
sf::Vector2i s = BoardAlignedSprite::toSquares(mouseCoords);
if(!m_game.hasStarted())
remove(s);
}
else if (m_iHandler->testEvent(event, "EndTurn"))
{
tryAndEndTurn();
}
else if (event.Type == sf::Event::MouseWheelMoved)
{
if(event.MouseWheel.Delta > 0)
{
m_selectedType = m_placementUI.goUp();
}
else
{
m_selectedType = m_placementUI.goDown();
}
}
else if (m_iHandler->testEvent(event, "Rabbit"))
//.........这里部分代码省略.........
示例15: Animate
SBI gra_screen::Animate(sf::RenderWindow &App)
{
if (Timer_c.GetElapsedTime()-osttime-korektatime>1)
{
korektatime=Timer_c.GetElapsedTime()-osttime;
}
osttime=Timer_c.GetElapsedTime()-korektatime;
for (int i=0;i<obiekty_il;i++)
{
(obiekty+i)->ZasTarcie(App.GetFrameTime(),ProgTarcia);
}
const sf::Input& Input = App.GetInput();
if (Input.IsKeyDown(sf::Key::B))
{
for (int i=0;i<obiekty_il;i++)
{
(obiekty+i)->SetV(0,0);
}
}
for (int i=0; i<gracz_il; i++)
{
bool cx=false;
bool cy=false;
int przyspGDoc;
bool czyuderz=(Input.IsKeyDown(gracze_ev[i][(int)Uderz].KeyCode));
if (czyuderz)
przyspGDoc=PrzyspGKop;
else
przyspGDoc=PrzyspG;
if (Input.IsKeyDown(gracze_ev[i][(int)Lewo].KeyCode))
{
gracze_ob[i].SetVX(gracze_ob[i].GetVX()-App.GetFrameTime()*przyspGDoc);
cx=true;
}
if (Input.IsKeyDown(gracze_ev[i][(int)Prawo].KeyCode))
{
gracze_ob[i].SetVX(gracze_ob[i].GetVX()+App.GetFrameTime()*przyspGDoc);
if (cx)
cx=false;
else
cx=true;
}
if (Input.IsKeyDown(gracze_ev[i][(int)Gora].KeyCode))
{
gracze_ob[i].SetVY(gracze_ob[i].GetVY()-App.GetFrameTime()*przyspGDoc);
cy=true;
}
if (Input.IsKeyDown(gracze_ev[i][(int)Dol].KeyCode))
{
gracze_ob[i].SetVY(gracze_ob[i].GetVY()+App.GetFrameTime()*przyspGDoc);
if (cy)
cy=false;
else
cy=true;
}
if (Input.IsKeyDown(gracze_ev[i][(int)Uderz].KeyCode))
{
if (GraczPowLock[i])
gracze_ob[i].PopV(MaxVGraczNorm);
else
gracze_ob[i].PopV(MaxVGraczKop);
}
else
{
gracze_ob[i].PopV(MaxVGraczNorm);
GraczPowLock[i]=false;
}
}
/*for (int i=0; i<obiekty_il; i++)
{
(obiekty+i)->Animate(App.GetFrameTime(),bg,bd,bl,bp,bramka);
}
for (int i=0; i<obiekty_il-1; i++)
for (int j=i+1; j<obiekty_il; j++)
if (czy&&(obiekty+i)->ZderzenieAnaliz(App.GetFrameTime(),obiekty+j,bg,bd,bl,bp,bramka))
{
cout << "ZDERZENIE!!!";
czy=true;
}*/
double anisum=0;
double tmp;
double mintmp=10000000;
double mini;
int dodnum1,dodnum2;
int num1,num2;
num1=0;
while(num1!=-1)
{
num1=-1;
num2=-1;
mini=1000000;
for (int i=0; i<obiekty_il-1; i++)
for (int j=i+1; j<obiekty_il; j++)
{
tmp=(obiekty+i)->TZderzenia(obiekty+j);
//.........这里部分代码省略.........