Skip to content

Getting Started

Matt Styles edited this page Jun 21, 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 xy::Message&);

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

and, optionally, override initialise() and finalise(). These are executed on startup and exit respectively, and should be used for any potentially non-exception safe code not suitable for the constructor or destructor. When using the state stack you'd want to clear it in finalise() for example.

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 which 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, from which all drawing code should be called.

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