Groogy / rbSFML

Ruby bindings to SFML
Other
44 stars 5 forks source link

Event::Closed does not equal Event::Closed #30

Closed silentdth closed 12 years ago

silentdth commented 12 years ago

Take the below code for example, if you close the window using the red 'X' (Windows 7 32bit) the event described with 'puts event' is 'Event::Closed', but the window does not close:

# The main loop - ends as soon as the window is closed
while window.open?
  # Event processing
  window.each_event do |event|
    puts event
    if event === Event::Closed
      window.close
    end
  end

  # OpenGL drawing commands go here...

  # End the current frame and display its contents on screen
  window.display
end
Groogy commented 12 years ago

This could possibly be a bug in SFML I'll have a look at it when I get some time.

Groogy commented 12 years ago

Can you check if you get any event? Or is it just specifically Event::Closed?

silentdth commented 12 years ago

I just retested it, It doesn't work for any events. I just tried Event::MouseLeft.

I know its the correct Event because I output it to the console.

EG: puts event

produces SFML::Event(MouseLeft)

then do something with a condition, like so: if event === Event::MouseLeft puts "MADE IT!" window.close end

It never enters the conditional block.

Hope that helps.

silentdth commented 12 years ago

This is interesting, using irb.

>> Event::MouseMove === Event::MouseMove
=> false
>>

And then...

>> Event::MouseMove == Event::MouseMove
=> true
Groogy commented 12 years ago

Have you tried with the #== operator? I see there's a === operator for one of the event types classes(not instance method). I'll have a look at the code in SFML::Event and see what it is actually supposed to do. ^^

silentdth commented 12 years ago

Interesting:

>> Event::MouseMove #== Event::MouseMove
=> SFML::Event::MouseMove

>> Event::Closed #== Event::Closed
=> #<SFML::Event::Type:0x200d228 @id=0>

Ok, thanks. I might be doing something wrong!

Groogy commented 12 years ago

Erhm the "#" means the instance method :P

So if I write SFML::Event#== then that means the "==" method on an Event instance.

Though the thing I want you to try out is: event.type == SFML::Closed

Though I think this might be wrong. Because you got an instance from writing: Event::Closed. Which is very wrong. I'll look at it when I get home.

Groogy commented 12 years ago

Fixed in this commit f1e489bd482d009781fa739cf7a9534a11ae3422

Let me know if it works for you. Though remember: event == SFML::Event::Closed is an invalid comparison. They are two different types. What you want to do is event.type == SFML::Event::Closed. I could make so the first one works as well. Though the second one is the one we implemented as this is how it works in C++ SFML ;)

silentdth commented 12 years ago

Thanks Groogy!

That works :)