Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SetDrawingBounds help  (Read 2592 times)

0 Members and 2 Guests are viewing this topic.

OutlawLee

  • Jr. Member
  • **
  • Posts: 50
  • This is my personal text. Dont read it.
    • View Profile
    • Email
SetDrawingBounds help
« on: May 13, 2012, 12:21:55 pm »
I was working on Tiled system, and i managed to convert it to 2.0, but now the only problem is

Code: [Select]
Level level;
level.LoadFromFile("Maps/spawn.tmx");

sf::FloatRect rect2(0, 0, 2048, 1536);
level.SetDrawingBounds(rect2); // THIS

The tutorial said differently:
Code: [Select]
Create an instance of Level.

Level level;

To load a map file,

level.LoadFromFile("example.tmx");

You MUST set drawing bounds before attempting to display the level.

level.SetDrawingBounds(somesfview.GetRect());

I recommend using an sf::View to "scroll" the map, rather than moving the map itself. This way you don't have to worry about objects (NPCs etc) on your map moving (or not) correctly.
You will find you need to implement some system to only move the view by whole numbers, otherwise you will see gaps between tiles.

Then to draw you simply pass your renderwindow to the Draw function.

level.Draw(window);


Can someone write me with sf::View ? I dont know how to since there isnt a GetRect() anymore.

Deftwun

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: SetDrawingBounds help
« Reply #1 on: May 17, 2012, 03:42:40 am »
I dont know about the first part not sure how your level class is implemented but the GetRect() function in sf::view has been changed to getviewport(). this will return a floatrect same as GetRect(). Although I think that might have been modified too. I think in sfml 1.6 a floatrect contained a 'right' and a 'bottom' member.
« Last Edit: May 17, 2012, 03:46:13 am by Deftwun »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SetDrawingBounds help
« Reply #2 on: May 17, 2012, 10:09:59 am »
Quote
the GetRect() function in sf::view has been changed to getviewport(). this will return a floatrect same as GetRect().
Wrooooooooooooooooong.
Use the center and size to reconstruct the view rectangle.
Laurent Gomila - SFML developer

Deftwun

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: SetDrawingBounds help
« Reply #3 on: May 17, 2012, 06:53:52 pm »
really? Sorry I think my noobishness is showing but how do the two differ?
I looked like he was using the floatrect of the view as the drawing bounds. so...

Wouldn't this:
sf::view mView;
level.SetDrawingBounds(mView.getviewport());

be the same as reconstructing the rectangle using center and size, except less code?

« Last Edit: May 17, 2012, 07:07:31 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SetDrawingBounds help
« Reply #4 on: May 17, 2012, 07:07:20 pm »
The viewport is a totally different thing, have you read what it is in the documentation?
Laurent Gomila - SFML developer

Deftwun

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: SetDrawingBounds help
« Reply #5 on: May 17, 2012, 08:19:16 pm »
Not well enough I suppose. I just assumed and made myself look like an idiot.
Correct use of viewport here:
http://sfml-dev.org/documentation/2.0/classsf_1_1View.php#a8eaec46b7d332fe834f016d0187d4b4a

 Sorry for the bad info..