Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Bindings - other languages
»
DotNet
»
SFML Events w/C#.NET
Print
Pages: [
1
]
Author
Topic: SFML Events w/C#.NET (Read 12342 times)
0 Members and 1 Guest are viewing this topic.
WaterNode
Newbie
Posts: 8
SFML Events w/C#.NET
«
on:
January 27, 2013, 09:22:58 pm »
I'm trying to figure out how to register events in SFML.NET, and I'm clueless. I'm looking for tutorials, but a no go.
This is my code so far:
using
System
;
using
SFML.Audio
;
using
SFML.Window
;
using
SFML.Graphics
;
namespace
Example
{
class
Program
{
static
void
OnClose
(
object
sender, EventArgs e
)
{
// Close the window when OnClose event is received
RenderWindow window
=
(
RenderWindow
)
sender
;
window
.
Close
(
)
;
}
static
void
Main
(
string
[
]
args
)
{
// Create the main window
System.
Threading
.
Thread
.
Sleep
(
1000
/
50
)
;
RenderWindow window
=
new
RenderWindow
(
new
VideoMode
(
1024
,
768
)
,
"Game"
)
;
window
.
Closed
+=
new
EventHandler
(
OnClose
)
;
// Load a sprite to display
Texture texture
=
new
Texture
(
"Graphics/mainCharStand.PNG"
)
;
Sprite sprite
=
new
Sprite
(
texture
)
;
// Start the game loop
while
(
window
.
IsOpen
(
)
)
{
// Process events
window
.
DispatchEvents
(
)
;
// Clear screen
window
.
Clear
(
)
;
// Draw the sprite
window
.
Draw
(
sprite
)
;
// Update the window
window
.
Display
(
)
;
}
}
}
}
Is this how you register events? Or am I mistaken.
window
.
Closed
+=
new
EventHandler
(
OnClose
)
;
Logged
Hiura
SFML Team
Hero Member
Posts: 4321
Re: SFML Events w/C#.NET
«
Reply #1 on:
January 27, 2013, 10:02:38 pm »
I never used SFML.Net but it looks the same as
this example
so I would say it's correct.
Isn't it working ? What's your issue ?
Logged
SFML / OS X developer
SymegPL
Newbie
Posts: 13
Re: SFML Events w/C#.NET
«
Reply #2 on:
January 27, 2013, 10:05:47 pm »
Yes. When window is closed then OnClose method was triggered.
Logged
WaterNode
Newbie
Posts: 8
Re: SFML Events w/C#.NET
«
Reply #3 on:
January 27, 2013, 10:17:36 pm »
Thank you for clarifying.
Logged
krzat
Full Member
Posts: 107
Re: SFML Events w/C#.NET
«
Reply #4 on:
January 27, 2013, 10:45:25 pm »
You can also write:
window
.
Closed
+=
OnClose
;
or
window
.
Closed
+=
(
s,a
)
=>
window
.
Close
(
)
;
Logged
SFML.Utils
- useful extensions for SFML.Net
PlankSkills
Guest
Re: SFML Events w/C#.NET
«
Reply #5 on:
March 27, 2020, 01:41:04 pm »
There is something wrong with your code:
"window.isOpen()"
window.isOpen isn't a method, you should use it like this:
"window.isOpen" // No Parenthesis
Logged
Print
Pages: [
1
]
SFML community forums
»
Bindings - other languages
»
DotNet
»
SFML Events w/C#.NET