Skip to content

Attach events to scenes

Julien Tauran edited this page Dec 27, 2018 · 3 revisions

Currently a scene can support theses events:

  • Key pressed: event_key_pressed
  • Mouse pressed: event_mouse_pressed
  • Mouse released: event_mouse_released
  • Mouse moved: event_mouse_moved
  • Mouse wheel scrolled: event_mouse_wheel_scrolled
  • Text entered: event_text_entered
  • Tick: event_tick
  • Scene initialization: event_init
  • Scene initialization post: event_init_post

To attach an event to a scene you will have to create a function with the name you want but with the required argument.
In this example we will attach a key press event.

void key_press_event(bs_event_key_pressed_t event)
{
	bs_frame_t *frame = event.frame;

	if (event.event.code == sfKeyEscape) {
		sfRenderWindow_close(frame->window);
	}
}

scene->event_key_pressed = &key_press_event;
Clone this wiki locally