Skip to content

Getting Started

Matt Styles edited this page Feb 7, 2016 · 11 revisions

Once you have compiled the library with the compiler of your choice, simply link it to your new project, along with the SFML libraries and Box2D library. xygine requires all five components of SFML - system, windows, graphics, audio and networking, and uses Box2D for its default physics implementation.

To use the library create a new class which inherits xy::App and implement the virtual functions:

void handleEvent(const sf::Event&);
void handleMessage(const Message&);

void registerStates();
void updateApp(float dt);
void draw();

and, optionally, override finalise() if you have any code which requires clean up on program exit.

handleEvent()

and

handleMessage()

pass on any window event and system messages respectively. See messages for more detail.

registerStates()

is needed when using the state stack implementation of xygine. When creating new game states (deriving from xy::State) they need to be registered with the StateStack instance of your game. See the Example directory for a demo project which shows how to create a basic state uses uses the xygine UI controls to create a menu.

updateApp()

passes on the current elapsed game time, fixed at 1/60 second. This is used to update logic when xygine is running.

draw()

is the top level draw function. getRenderWindow().clear() and getRenderWindow().display() should both be called here, with your drawing code called in between.

Once you have created your app class, instantiate it in your main() function and call run()

int main()
{
	MyApp game;
	game.run();
	return 0;
}
Clone this wiki locally