Book Image

SFML Essentials

By : Milcho G. Milchev
Book Image

SFML Essentials

By: Milcho G. Milchev

Overview of this book

<p>SFML is a cross-platform, object-oriented multimedia API that is written in C++. It provides a simple interface to ease the development of games and multimedia applications.</p> <p>This book will guide you through everything you need to know about building a 2D game in SFML. Concepts such as Sprites, Textures, Animation, and Cameras are explored in depth and finally the book ends with advanced topics like shaders and networking. You will also learn how to play sound and music on top of the gameplay. Every step through the journey is filled with examples in C++ to guide you in the right direction. By the end of the book you will feel confident about creating 2D games with SFML, without investing too much time on it.</p> <p>This book contains a set of fast-paced tutorials about the core features of SFML.</p>
Table of Contents (14 chapters)

Sound versus music


At first glance, the existence of these two classes might seem odd, but they ultimately serve different purposes, and it's all due to how they are implemented.

The Sound class loads all of its data into system memory, and this makes playing the audio sample very quick. The Music class, on the other hand, opens a stream to a file on the hard drive (or the RAM) and loads small chunks of data, which are played one after the other. Due to its design, the Music class has a playback delay due to transferring the data at such a slow place.

Both the classes provide different benefits—the Sound class almost instantly plays, but takes a lot of system memory, whereas the Music class is slower to play, but doesn't use much RAM at all. As such, both the classes are useful in different situations. For example, if the audio file is small enough to store in system memory, we should load it using the Sound class. This is applicable when the sound is to be played instantaneously after we...