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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Nischal744

Pages: [1]
1
General / Re: How to draw Objects at a fixed position ??
« on: January 04, 2016, 08:25:34 am »
Is your window really moving? This shouldn't affect the positioning of the drawing relative to the window.
It's more likely that you mean that your view is moving. Are you moving the view, the sprite, or both?
If you want to draw at the same place as the top left of the sprite, you can use the same coordinate as the sprite (assuming you still have its origin at the top-left).
If you want to draw at the top-left of the window, you can know what the coordinate should be or you could use one of these two things:
sf::Vector2f topLeftOfWindow = window.getView().center - window.getView().width / 2.f;
sf::Vector2f topLeftOfWindow = window.mapPixelToCoords(sf::Vector2i(0, 0));

You may find the tutorial on views useful


Well the thing that's moving is the background sprite. But when I moved the shapes together with the background sprite, that did the trick. Thanks for you help!!

2
General / How to draw Objects at a fixed position ??
« on: January 01, 2016, 04:40:12 pm »
Hi,
I'm working on to develop a game in which the default window size is 800 x 600, and the background sprite I'm using is a 4000 x 600 (Alternative to having 5 sprites of 800 x 600). So, I'm basically moving the sprite when a key is pressed. The 4000 x 600 sprite is positioned at (-2000, 0), i.e the starting view is right at the middle of the sprite. Now the part I'm having issues with; I'm trying to draw some objects(shapes) at the leftmost end of the sprite at the start of the game and I'm able to draw them. But, when I press the assigned key and the sprite moves to the leftmost end, the drawn objects are no longer there, this I think is because the shapes are drawn relative to the window's position. So, when I reach to the leftmost end, the shapes also move by the same distance as I've covered while moving from middle to the left.
                         I was wondering if there is any way to draw the shapes and keep them fixed so that they won't get affected by the movement of the window.
Thanks for any Help!! Cheers!!  8)


Pages: [1]