Skip to content

Getting Started

Matt Styles edited this page Oct 28, 2015 · 11 revisions

xygine compiles to a static library by default when using the included CMake file. Linux / Mac maybe be able to compile a shared library (I haven't tried it), but MSVC currently does not export any functions. Once you have compiled the library with the compiler of your choice, simply link to your new project, along with the SFML libraries. xygine requires all five components of SFML - system, windows, graphics, audio and networking.

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 pauseApp(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.

Both

updateApp()

and

pauseApp()

pass on the current elapsed game time, fixed at 1/60 second. These are used to update logic when xygine is either running or paused, for example you may wish to make menus updatable while the game itself is paused.

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