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.


Topics - Steef435

Pages: [1]
1
Graphics / [Solved]Get the focus of a window
« on: November 10, 2012, 01:50:44 pm »
Hello all,

At the moment I'm trying to put everything I've learned in a small project, just a point and click game.
It's like duck hunt, a duck flies through the air and you have to "shoot" it by clicking on it.
Here's my problem:
Every loop (1/25sec) I check if the left mouse button is down and if the "cooldown" of the gun is passed.
If that's true I check if the duck is shot etc.
This all works fine.
But when I click outside of my window, my program takes that as a attempt to shoot the duck, this ruins my whole system because I want to keep track of the longest sequence of good shots etc.
What I'm trying to achieve is this:
if ((WindowIsFocussed) && (MouseButtonIsDown) && (CooldownPassed))
//Check if duck is shot etc.

So I'm searching for a function like bool sf::Window::isFocussed() or getFocus, whatever.

If I search for this function I find a request topic, so I guess the function is not yet implemented.

Is there any workaround for me to do this? I don't like to use the event system because I want to be able to just hold the mouse button.
I can think of using a bool to keep track of every time I get an LostFocus and GainedFocus event, but I was just wondering if there was a more neat way to achieve this.
I also thought of creating my own class derived from sf::RenderWindow, but after a look at the files my head hurt ;D

Thanks in advance!
Steef

2
Graphics / [solved]Global sf::Renderwindow used in derived class
« on: November 04, 2012, 05:11:10 pm »
Hello all,

Perhaps I better say this first: I'm not sure if this is a question related to sfml or if I'm just being stupid at C++.
I fear for the latter ;D

I'm using the latest snapshot built on Ubuntu 12.10, my compiler is gcc.

This is my problem:
I'm trying to learn about different techniques for state-changing(from intro to menu etc.).
The one I'm now trying to implement uses a base GameState class which will be derived by all the states(not exceptional).
So that class, which looks something like this:
class Gamestate
{
    GameState(){};
    virtual void logic() = 0;
    virtual void input() = 0;
    virtual void render() = 0;
}
I derive in my Intro class.
I have a global sf::RenderWindow* window which I use in my derived class.
My input()-function looks something like this:
void input()
{
    sf::Event event;
    while (window->pollEvent(event))
    {
         //process input...
    }
}
This all compiles fine but when I try to run this program it gives me a segmentation fault(core dumped).
I'm pretty sure it has nothing to do with my state-system, the debugger tells me the program gives the error after the first call to the RenderWindow out of my Intro-class, in the input function at the first line of pollEvent in Window.cpp.

Yes, I did initialize(is that the right word?) the RenderWindow, I did even call create() right after that just to be sure.

Again, I'm still quite new to C++ and sfml, so it could be something stupid I overlooked.

It would be very nice if someone could help me out with this, I'm already looking at this error for over an hour...

Regards,
Steef

Pages: [1]