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 - sec_goat

Pages: [1] 2
1
General / SFML 2.0 sf::Mouse::GetPosition() returning wierd coords.
« on: November 23, 2011, 10:01:46 pm »
Well Don't I feel stupid!

If you don't feed the GetPosition() a RenderWindow it gives you coords relative to your overall window position and not the applications position.

Code: [Select]

sf::Event currentEvent;
    while(m_GameWindow.PollEvent(currentEvent))
    {
        if(currentEvent.Type == sf::Event::MouseButtonPressed)
        {
            sf::Vector2i mouse_pos = sf::Mouse::GetPosition(sf::RenderWindow);
            bool clicked = TravelBoard.CheckForTilesClicked(mouse_pos);
            std::cout<<clicked<<std::endl;

        }
}

2
General / SFML 2.0 sf::Mouse::GetPosition() returning wierd coords.
« on: November 23, 2011, 09:59:30 pm »
Hello all,

I am trying to return my mouse cursor position so I can check to see if something is clicked or not.

Currently this is my code
Code: [Select]

 sf::Event currentEvent;
    while(m_GameWindow.PollEvent(currentEvent))
    {
        if(currentEvent.Type == sf::Event::MouseButtonPressed)
        {
            sf::Vector2i mouse_pos = sf::Mouse::GetPosition();
            bool clicked = TravelBoard.CheckForTilesClicked(mouse_pos);
            std::cout<<clicked<<std::endl;

        }
}


when I print my pos.x and pos.y they are much higher than they should be, for instance if I click as close to the top left of the screen as possible i get something like (1028,698) instead of something closer to (0,0).

What am i doing wrong in this instance to get a larger position than the one I should be getting?

Thanks!

3
General / SFML 2.0 sf::Rect usage.
« on: November 18, 2011, 09:39:11 pm »
Quote from: "Laurent"
Why would a sprite update its subrect position? The subrect is the area of the texture that the sprite displays, it mustn't move.

If you want to get the bounding rectangle of your sprite in the 2D scene, you must compute it yourself. There are some threads on this forum that explain how to do this.


I appreciate it, I believe I have some pretty sound logic on how to compute that, I was just not sure if that was needed.
I am coming to C++ and SFML from Python and Pygame. Pygame had a rect object attached to sprite or something similar so yo could always call sprite.rect to find the area it filled.

Thanks for the point in the right direction, I will get on it!  :D

4
General / SFML 2.0 sf::Rect usage.
« on: November 18, 2011, 09:13:16 pm »
Are sf::Rects attached or managed by another class like sf::Sprite or are they self managed?
For instance if sf::Rect is part of sf::Sprite, does sf::Sprite update the sf::Rect position so we can easily do the sf::Rect< T >::Intersects,
or do I have to create and manage  sf::Rect objects manually?
   
I am looking into the documentation but I am not seeing anything that directly answers this question, so I will assume I need to create and manage rect locations manually.

5
General / [SOLVED] SFML 2.0 restricitng how far sf::View can move.
« on: November 18, 2011, 07:56:32 pm »
It seems I have solved the problem, not 100% bug free but here is the final code that will limit the ViewPort movement to a set rectangular area

Code: [Select]

void SetView()
{

    //get players posiiton and set current view to  center on him

    sf::Vector2f player_pos =player->GetPosition();

    //now get view center and size and make sure it isnt goign off the map
   
    sf::Vector2f view_center = currentView.GetCenter();
    sf::Vector2f view_size = currentView.GetSize();

    if(player_pos.y - (view_size.y /2) < 0) //check to see if viewport y is less than 0 on y axis
    {
        view_center.y = view_size.y /2;
        view_center.x = player_pos.x;
        currentView.SetCenter(view_center);
    }

    if(player_pos.y + (view_size.y /2)> SCREEN_HEIGHT) //check to see if viewport y is greater than height.
    {
        view_center.y = SCREEN_HEIGHT - (view_size.y /2);
        view_center.x = player_pos.x;
        currentView.SetCenter(view_center);
    }

    if(player_pos.x - (view_size.x /2) < 0) //check to see if viewport  x will be less than 0 on x axis
    {
        view_center.x = view_size.x / 2;
        //view_center.y = player_pos.y;
        currentView.SetCenter(view_center);
    }

    if(player_pos.x + (view_size.x /2) > 2115) //check to see if viewport x is greater than map size 2115
    {
        view_center.x = 2115 - (view_size.x /2);
        //view_center.y = player_pos.y;
        currentView.SetCenter(view_center);
    }

}

6
Graphics / Some help with viewports?
« on: November 17, 2011, 09:43:45 pm »
I am by no means an expert. but try initializing your view and viewport a bit differently.

I declare my view in my class header file, then reset it and set the view port later.

Code: [Select]

static sf::View currentView;

currentView.Reset(sf::FloatRect(0, 0, 768, 768));

currentView.SetViewport(sf::FloatRect(0.f, 0.f, 0.75f, 1.f));

//I then move my viewport by changing it's center
currentView.SetCenter(100,100);

//then update the renderwidnows view
window.SetView(currentView);


this appears to work just fine for me.

EDIT:

it appears if I just change your viewport init then it works fine, not sure exactly why

Code: [Select]

#include "SFML\Graphics.hpp"

int main()
{
   sf::RenderWindow window;
   window.Create(sf::VideoMode(800,600), "sf::Viewport test");

   sf::View view = window.GetView();
   view.SetViewport(sf::FloatRect(0, 0, 1, 1));
   window.SetView(view); //if I comment out this line I get the expected black window with white circle in the middle

   sf::Shape shape = sf::Shape::Circle(sf::Vector2f(window.GetWidth() /2, window.GetHeight() /2), 50, sf::Color::White);

   while(window.IsOpened())
   {
      sf::Event e;
      while(window.PollEvent(e))
      {
         if(e.Type = sf::Event::Closed)
            window.Close();
      }

      window.Clear();
      //window.SetView(view);
      window.Draw(shape);
      window.Display();
   }

   return EXIT_SUCCESS;
}

7
General / [SOLVED] SFML 2.0 restricitng how far sf::View can move.
« on: November 17, 2011, 09:03:39 pm »
Quote from: "Tex Killer"
Take the second if and add this:

Code: [Select]
else
{
    view_center.x = view_size.x / 2;
    view_center.y = player_pos.y;
    View.SetCenter(view_center);
}


You might also want to check your variable declarations... Each one's type is written differently.


Very nice, that seems to work in the specific instance i supplied. as for my type's being different, I forgot to double check those when I typed them in here. They are in fact correct in my real code.

Now I tried to expand on that code and I am running into some problems, once again probably my use of loops and not doing it correctly.
here is what I have implemeneted, it works on the y axis, but not the x, any ideas why?

Code: [Select]

if(player_pos.x - (view_size.x /2) < 0)
    {
        view_center.x = view_size.x / 2;
        view_center.y = player_pos.y;
    }
    else if(player_pos.x + (view_size.x /2) > 2115)
    {
        view_center.x = 2115 - (view_size.x /2);
        view_center.y = player_pos.y;
    }
    if(player_pos.y - (view_size.y /2) < 0)
    {
        view_center.y = view_size.y /2;
        view_center.x = player_pos.x;
    }
    else if(player_pos.y + (view_size.y /2)> 800)
    {
        view_center.y = 800 - (view_size.y /2);
        view_center.x = player_pos.x;
    }
    currentView.SetCenter(view_center);

8
General / [SOLVED] SFML 2.0 restricitng how far sf::View can move.
« on: November 16, 2011, 10:47:43 pm »
This isn't necessarily a SFML related question, more likely I just am having a hard time wrapping my head around the logic needed to restrict the sf::View movement.

I want the view to move with the player, however I do not want it to display past a certain set of coordinates, whatever my play field will be (0,0) to (800,2000) or whatever.

Currently I use GetPosition on a player sprite and then set the center of my view to the same position.

Then I try to check the edges of the view against coords to stop it from moving, which I am doing all wrong so far.

Code: [Select]


sf::Vector2f player_pos = PlayerSprite.GetPosition();
sf:vector2f view_center = View.GetCenter();
sfVector2f view_size = View.GetSize();

if(view_center.x - (view_size.x /2) >= 0)
{
   View.SetCenter(player_pos)
}


I have also tried
Code: [Select]


if(player_pos.x - (view_size.x /2) >= 0)
{
   View.SetCenter(player_pos)
}

This appears to work if I don't go too far left, when I do the view freezes, because my equation obviously will never equal or go above 0;

I guess I am looking for some advice to stop the view from moving based on player position. I know i need some combonation of Player position, view size and position. But so far my attempts have all been thwarted.

Thanks!


 :P

9
General / Building SFML 2.0
« on: November 16, 2011, 04:37:39 pm »
Quote from: "Laurent"
Quote
I don't want to thread hijack

But you did :roll:
If my answer doesn't solve your problem, please open a new thread.

Quote
However I do not see any folder that has the same contents as when I download and use SFML 1.6

You must install SFML.

It's clearly written in the tutorial...
Quote
install
Installs SFML to the path defined in the CMAKE_INSTALL_PREFIX option. It copies the SFML libraries and headers, as well as examples and documentation if the BUILD_EXAMPLES and BUILD_DOC options are enabled. After installing, you get a clean distribution of SFML, just as if you had downloaded the SDK or installed it from the system repositories.


I apologize, I meant I don't want to take this off topic, but I also don't want to flood the forums with duplicate posts. I will go back and re-read the tutorial and try to comprehend it better, and as always thank you for your hard work and help!

EDIT: Aha yes, I should have known that Make Install! it just threw me because I am on windows and not used to having to make or make install on windows. . .

10
General / Building SFML 2.0
« on: November 16, 2011, 04:28:22 pm »
Quote from: "Groogy"
Have you followed this tutorial? http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php


I don't want to thread hijack, but I am having some issues comprehending the completed product after i use Cmake for SFML 2.0.

I am left with 2 folders: the one i unzipped to and the one I made to.
However I do not see any folder that has the same contents as when I download and use SFML 1.6.

How do I go from this tutorial to the setting it up for your compiler tutorial a-la 1.6 http://www.sfml-dev.org/tutorials/1.6/start-cb.php

thanks!

11
Graphics / Help with logic behind displaying game map?
« on: November 16, 2011, 03:17:30 pm »
Quote from: "Laurent"
Quote
My problem is that when I try to feed my view different rectangles to initialize it, it always ends up filling the whole RenderWindow and not just say 800x600 or whatever I set them to.

The rectangle that you pass to the view is the source rectangle, ie. the area of the scene that will be mapped to the entire render window. It defines what you see, not where you see it.
To define the destination rectangle, ie. the area of the render window where the source rectangle will be mapped, you need to play with the viewport (SFML 2 only).


Awesome thanks! I will have to look at building SFML 2 again, I had some issues following the tutorial because I did not make my make file correctly I will bet you.

12
Graphics / Help with logic behind displaying game map?
« on: November 16, 2011, 02:40:27 pm »
Quote from: "Tex Killer"
You are looking for the views.
http://www.sfml-dev.org/tutorials/1.6/graphics-views.php


I am missing something about the view, probably obvious and simple as I tend to over-think my problems. here is what I am doing so far ( not a the complete code sample but you should get the gist).

Code: [Select]

sf::View currentView; //create the view
currentView.SetFromRect(sf::FloatRect(0, 0, 1000, 1000));

//move the view to center on player
sf::Vector2f temp_pos = player->GetPosition();
currentView.SetCenter(temp_pos);


My problem is that when I try to feed my view different rectangles to initialize it, it always ends up filling the whole RenderWindow and not just say 800x600 or whatever I set them to.

How do I go about implementing this in a more correct manner?

13
Graphics / new Question!
« on: November 15, 2011, 09:39:12 pm »
Ok so I am making a little bit of progress in regards to displaying my map and handling images etc.

The new question I have that is in this same vein is, how do I create a section for specific types of rendering? I.E. I have a 1024x768 window and I would like to set aside 600x400 for rendering my map. I tried creating a new sf::RenderWindow, but that creates a whole new window.  I think I am looking for something like an area. . . Thanks again every one! :D

14
Graphics / Help with logic behind displaying game map?
« on: November 15, 2011, 06:48:10 pm »
Quote from: "Nexus"
Quote from: "sec_goat"
I had read somewhere about the image / sprite separation, so I am currently loading 1 image and 1 sprite per tile. This appears to work fine by drawing the same sprite over and over in different positions.
Do you mean one image in total, or one per tile? The intention is to have as few images as possible, and to share them among multiple lightweight sprites. That is, tiles that look the same only require one common image.

Quote from: "sec_goat"
I am currently trying to figure out how to only draw what is visible, I am thinking that the SFML::View may be a good way to do so, but I am not sure and will be playing around with that in the coming days.
You can find it out by testing whether the object coordinates are outside of the screen. Usually, this amounts to 4 inequations per object.


Thanks Nexus, I am notoriously bad at not communicating clearly. I am loading 1 image per tile type, and then rendering he 1 sprite per tiletype over and over again, seems to work well so far.  I think I understand the way to make sure I am not rendering outside the players view.

Thanks for everyone's help!

15
Graphics / Help with logic behind displaying game map?
« on: November 12, 2011, 01:29:25 pm »
Quote from: "Nexus"
Don't use more sf::Image objects than necessary. Share images among multiple sprites that use them. sf::Sprite is -- in contrary to sf::Image -- a lightweight class which can be copied fast.

And only draw the visible tiles. But redraw everything which is visible, there's mostly no gain in trying to find out what has changed and what hasn't.


I had read somewhere about the image / sprite separation, so I am currently loading 1 image and 1 sprite per tile. This appears to work fine by drawing the same sprite over and over in different positions.

I am currently trying to figure out how to only draw what is visible, I am thinking that the SFML::View may be a good way to do so, but I am not sure and will be playing around with that in the coming days.

Thanks!

Pages: [1] 2
anything