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)

Preface

SFML Essentials is a practical set of tutorials about the Simple and Fast Multimedia Library (SFML) that teaches you how to use the library quickly and easily. The book establishes the core concepts of game development by providing the best practices in this field.

Game development can be a difficult topic to understand. SFML Essentials will provide enough knowledge about SFML for you to start implementing your ideas as soon as possible. This book also includes a number of fully working examples, which you can use and modify to suit your needs.

What this book covers

Chapter 1, Getting Started with SFML, is an introductory chapter about the SFML library. It goes through the process of creating a window and rendering basic shapes on the screen. This chapter concludes with a functional mini-game, the code of which is explained in detail.

Chapter 2, Loading and Using Textures, introduces the concept of sprites and textures and their interaction with the window. At the end of this chapter, the problems of resource management are tackled by building a robust asset manager.

Chapter 3, Animating Sprites, builds on the sprite class by animating it with spritesheets. A fully functional Animator class is constructed by the end of this chapter. This class can also be used outside the context of this book.

Chapter 4, Manipulating a 2D Camera, introduces the concept of cameras in a scene and the ways they can be interacted with. This chapter also discusses direct rendering with OpenGL on an SFML window.

Chapter 5, Exploring a World of Sounds and Text, discusses the audio and text components of a game. The concept of spatialization (3D audio) is covered as well.

Chapter 6, Rendering Special Effects with Shaders, dives into the topic of shaders and their uses in special effects. Postprocessing is briefly covered by giving an example of a pixelation shader.

Chapter 7, Building Multiplayer Games, discusses the topic of networking. After a brief introduction, the transport layer (TCP and UDP sockets) is explored. A working networking example between two PCs is presented at the end of this chapter.

What you need for this book

For this book you will require Microsoft Visual Studio 2012 Express for Windows Desktop, which can be downloaded from http://www.microsoft.com/en-gb/download/details.aspx?id=34673. You also need to install SFML v2.1 Visual C++ 11 (2012) 32-bit from http://sfml-dev.org/download/sfml/2.1/.

You also require a graphics card capable for running at 1024 x 768 pixels or a higher display resolution, and is compatible with OpenGL 2.0.

Who this book is for

SFML Essentials is for people who have experience in the field of game programming but want to use SFML for their next project. Perhaps you have an idea for a game, but your current environment is too slow to accommodate the needs of your game, or you want a cross-platform solution in your favorite language. In either case, this book will quickly guide you towards your goal. We assume that you possess a very basic understanding of game development, but solid understanding in at least one of the supported languages is required.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and explanations of their meanings.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "This is the reference that initializes the member's Sprite& field."

A block of code is set as follows:

sf::Uint32 style = sf::Style::Titlebar | sf::Style::Close;

New terms and important words are shown in bold.

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reference images

The images used inside this book have been taken from the following locations:

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/7326OS_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.