Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9018879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:38:33+00:00 2026-06-16T04:38:33+00:00

I need to find the equivalent of SetFromRect() for SFML 2.0. I’m using it

  • 0

I need to find the equivalent of SetFromRect() for SFML 2.0. I’m using it in a camera class where I am updating the position of the rectangle where the sprite can move freely. Once it reaches the middle of the screen it will start scrolling the camera by re-updating the rectangle with the new co-ordinates.

void Camera::Update(int x, int y)
{
    cameraX = -(ScreenWidth / 2) + x;
    cameraY = -(ScreenHeight / 2) + y;

    std::cout << "cameraX: " << cameraX << std::endl;
    std::cout << "cameraY: " << cameraY << std::endl;

    if(cameraX < 0)
        cameraX = 0;
    if(cameraY < 0)
        cameraY = 0;

    CameraPosition.setViewport(sf::FloatRect(cameraX, cameraY, cameraX + ScreenWidth, cameraY + ScreenHeight));
    std::cout << "cameraX + ScreenWidth: " << cameraX + ScreenWidth << std::endl;
    std::cout << "cameraY + ScreenWidth: " << cameraY + ScreenWidth << std::endl;
}

That all works fine except for:

CameraPosition.setViewport(sf::FloatRect(cameraX, cameraY, cameraX + ScreenWidth, cameraY + ScreenHeight));

It’s obtaining all the right numbers but I think it’s the wrong function for it.

I did try reset() but it didn’t work either.

EDIT:

The correct code is:

CameraPosition.reset(sf::FloatRect(cameraX, cameraY, ScreenWidth, ScreenHeight));
CameraPosition.setViewport(sf::FloatRect(0,0,1,1));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:38:34+00:00Added an answer on June 16, 2026 at 4:38 am

    SFML 2.0 rectangle types were changed from (left, top, right, bottom) to (left, top, width, height). I make that mistake too all the time.

    To move the camera around all you need to do is to move the sf::View. In your code that is as simple as calling CameraPosition.setCenter(x, y);.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find the mode EXE/DLL was build looking at its headers. (Using
I'm trying to find the equivalent of PropertyInfo.AddValueChanged for FieldInfo. I basically just need
I cannot find any equivalent binded method for CALayer's initWithLayer:(layer) selector that I can
I was told about textRange in IE, but I can't find equivalent in other
I need to find exact equivalent of this two line Perl in Python 2.x
I need some help to find the equivalent of App.Path and App.EXEName in VB.Net
I have a resolute and unyielding need to find the MS AJAX equivalent of
I need to find window position and size, but I cannot figure out how.
Need to find the timestamp for the first minute of the first day of
I need to find a flexible solution for access control in PHP. In the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.