SFML Game Development
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
$22.94
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
$44.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • Develop a complete game throughout the book
  • Learn how to use modern C++11 style to create a full featured game and support for all major operating systems
  • Fully network your game for awesome multiplayer action
  • Step-by-step guide to developing your game using C++ and SFML
  • You can find the updated code files here

Book Details

Language : English
Paperback : 296 pages [ 235mm x 191mm ]
Release Date : June 2013
ISBN : 1849696845
ISBN 13 : 9781849696845
Author(s) : Artur Moreira, Jan Haller, Henrik Vogelius Hansson
Topics and Technologies : All Books, Game Development

Table of Contents

Preface
Chapter 1: Making a Game Tick
Chapter 2: Keeping Track of Your Textures – Resource Management
Chapter 3: Forge of the Gods – Shaping Our World
Chapter 4: Command and Control – Input Handling
Chapter 5: Diverting the Game Flow – State Stack
Chapter 6: Waiting and Maintenance Area – Menus
Chapter 7: Warfare Unleashed – Implementing Gameplay
Chapter 8: Every Pixel Counts – Adding Visual Effects
Chapter 9: Cranking Up the Bass – Music and Sound Effects
Index
  • Chapter 1: Making a Game Tick
    • Introducing SFML
      • Downloading and installation
      • A minimal example
    • A few notes on C++
    • Developing the first game
      • The Game class
    • Game loops and frames
      • Input over several frames
      • Vector algebra
      • Frame-independent movement
      • Fixed time steps
      • Other techniques related to frame rates
    • Displaying sprites on the screen
      • File paths and working directories
      • Real-time rendering
      • Adapting the code
    • Summary
    • Chapter 2: Keeping Track of Your Textures – Resource Management
      • Defining resources
      • Resources in SFML
        • Textures
        • Images
        • Fonts
        • Shaders
        • Sound buffers
        • Music
      • A typical use case
        • Graphics
        • Audio
        • Acquiring, releasing, and accessing resources
      • An automated approach
        • Finding an appropriate container
        • Loading from files
        • Accessing the textures
      • Error handling
        • Boolean return values
        • Throwing exceptions
        • Assertions
      • Generalizing the approach
        • Compatibility with sf::Music
        • A special case – sf::Shader
      • Summary
      • Chapter 3: Forge of the Gods – Shaping Our World
        • Entities
          • Aircraft
          • Alternative entity designs
        • Rendering the scene
          • Relative coordinates
          • SFML and transforms
          • Scene graphs
          • Scene nodes
          • Node insertion and removal
          • Making scene nodes drawable
          • Drawing entities
          • Connecting entities with resources
          • Aligning the origin
          • Scene layers
        • Updating the scene
          • One step back – absolute transforms
        • The view
          • Viewport
          • View optimizations
          • Resolution and aspect ratio
          • View scrolling
          • Zoom and rotation
        • Landscape rendering
          • SpriteNode
          • Landscape texture
          • Texture repeating
        • Composing our world
          • World initialization
          • Loading the textures
          • Building the scene
          • Update and draw
        • Integrating the Game class
          • The run() method
        • Summary
        • Chapter 4: Command and Control – Input Handling
          • Polling events
            • Window events
            • Joystick events
            • Keyboard events
            • Mouse events
          • Getting the input state in real time
            • Events and real-time input – when to use which
            • Delta movement from the mouse
          • Playing nice with your application neighborhood
          • A command-based communication system
            • Introducing commands
            • Receiver categories
            • Command execution
            • Command queues
            • Handling player input
            • Commands in a nutshell
            • Implementing the game logic
            • A general-purpose communication mechanism
          • Customizing key bindings
            • Why a player is not an entity
          • Summary
          • Chapter 5: Diverting the Game Flow – State Stack
            • Defining a state
            • The state stack
              • Adding states to StateStack
              • Handling updates, input, and drawing
                • Input
                • Update
                • Draw
              • Delayed pop/push operations
            • The state context
            • Integrating the stack in the Application class
            • Navigating between states
              • Creating the game state
              • The title screen
              • Main menu
              • Pausing the game
            • The loading screen – sample
              • Progress bar
              • ParallelTask
              • Thread
              • Concurrency
              • Task implementation
            • Summary
              • Chapter 7: Warfare Unleashed – Implementing Gameplay
                • Equipping the entities
                  • Introducing hitpoints
                  • Storing entity attributes in data tables
                  • Displaying text
                • Creating enemies
                  • Movement patterns
                  • Spawning enemies
                • Adding projectiles
                  • Firing bullets and missiles
                  • Homing missiles
                • Picking up some goodies
                • Collision detection and response
                  • Finding the collision pairs
                  • Reacting to collisions
                  • An outlook on optimizations
                • An interacting world
                  • Cleaning everything up
                  • Out of view, out of the world
                  • The final update
                • Victory and defeat
                • Summary
                • Chapter 8: Every Pixel Counts – Adding Visual Effects
                  • Defining texture atlases
                    • Adapting the game code
                  • Low-level rendering
                    • OpenGL and graphics cards
                    • Understanding render targets
                    • Texture mapping
                    • Vertex arrays
                  • Particle systems
                    • Particles and particle types
                    • Particle nodes
                    • Emitter nodes
                    • Affectors
                    • Embedding particles in the world
                  • Animated sprites
                    • The Eagle has rolled!
                  • Post effects and shaders
                    • Fullscreen post effects
                    • Shaders
                    • The bloom effect
                  • Summary
                  • Chapter 9: Cranking Up the Bass – Music and Sound Effects
                    • Music themes
                      • Loading and playing
                      • Use case – In-game themes
                    • Sound effects
                      • Loading, inserting, and playing
                      • Removing sounds
                      • Use case – GUI sounds
                    • Sounds in 3D space
                      • The listener
                      • Attenuation factor and minimum distance
                      • Positioning the listener
                      • Playing spatial sounds
                      • Use case – In-game sound effects
                    • Summary
                    • Playing multiplayer games
                    • Interacting with sockets
                      • TCP
                      • UDP
                      • Socket selectors
                      • Custom protocols
                    • Data transport
                    • Network architectures
                      • Peer-to-peer
                      • Client-server architecture
                        • Authoritative servers
                    • Creating the structure for multiplayer
                    • Working with the Server
                      • Server thread
                      • Server loop
                      • Peers and aircraft
                      • Hot Seat
                      • Accepting new clients
                      • Handling disconnections
                      • Incoming packets
                      • Studying our protocol
                      • Understanding the ticks and updates
                        • Synchronization issues
                    • Taking a peek in the other end – the client
                      • Client packets
                      • Transmitting game actions via network nodes
                      • The new pause state
                      • Settings
                      • The new Player class
                    • Latency
                      • Latency versus bandwidth
                      • View scrolling compensation
                      • Aircraft interpolation
                    • Cheating prevention
                    • Summary

                    Artur Moreira

                    Artur Moreira is a game development enthusiast who ultimately aims to start a new game development company in his home country. He has been programming games and game-related software for over 4 years. Most of the effort in that time was put in creating an open source game-making library with lots of flexibility and portability. The library is called Nephilim and is known for supporting all major desktop and mobile operating systems, making game development fully crossplatform and fast. Alongside this big project, he keeps making his own prototypes and games for educational and commercial purposes. Aside from the programming, he also puts some focus in creative areas such as 3D modeling, digital painting, and music composing.

                    Jan Haller

                    Jan Haller is a Master's degree student of Electrical Engineering and Information Technology. In his free time, he occasionally develops games in C++. He is also interested in the creation of graphics and 3D models. In 2008, Jan stumbled upon SFML. Since then, he has used the library for many of his works. One of his bigger projects was a 2D Jump'n'Run game, where the character has to find its way through different levels, defeating enemies and collecting various items. During the years, Jan has actively participated in the SFML community, getting a lot of insights into the development of SFML 2. He has also written a C++ library called Thor, which extends SFML by ready-to-use features such as particle systems or animations.

                    Henrik Vogelius Hansson

                    Henrik Vogelius Hansson has always been in love with both games and programming. He started his education fairly early and continued on into the indie scene with Defrost Games and their game Project Temporality. The next company that hired him was Paradox Development Studio where he got to work on titles such as Crusader Kings 2. Beside the game companies, Henrik has also been very active in the SFML community and has even provided a binding for Ruby called rbSFML.
                    Sorry, we don't have any reviews for this title yet.

                    Code Downloads

                    Download the code and support files for this book.


                    Submit Errata

                    Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                    Errata

                    - 4 submitted: last submission 05 Feb 2014

                    Errata type: Code | Page number: 23

                    In the code, the first processEvents() is wrong, only the one directly before the update() function call is supposed to be there. The correct code is as follows:

                    void Game::run()
                    {
                        sf::Clock clock;
                        sf::Time timeSinceLastUpdate = sf::Time::Zero;
                        while (mWindow.isOpen())
                        {
                            
                            timeSinceLastUpdate += clock.restart();
                            while (timeSinceLastUpdate > TimePerFrame)
                            {
                                timeSinceLastUpdate -= TimePerFrame;
                                processEvents();
                                update(TimePerFrame);
                            }
                            render();
                        }
                    }
                    

                     

                    Errata type: Code | Page number: 77

                    The code on page 77 should be as follows:

                    World::World(sf::RenderWindow& window)
                    : mWindow(window)
                    , mWorldView(window.getDefaultView())
                    , mWorldBounds(
                        0.f,                               // left X position
                        0.f,                               // top Y position
                        mWorldView.getSize().x,            // width
                        2000.f)                            // height
                    , mSpawnPosition(
                        mWorldView.getSize().x / 2.f,                        // X
                        mWorldBounds.height - mWorldView.getSize().y / 2.f)  // Y
                    , mScrollSpeed(-50.f)
                    , mPlayerAircraft(nullptr)
                    {
                        loadTextures();
                        buildScene();

                        mWorldView.setCenter(mSpawnPosition);
                    }

                     

                     

                     

                    Errata type: Code | Page number: 119

                    The code on page 119 is incorrect, the correct code is as follows (the change has been highlighted):

                     

                    void StateStack::handleEvent(const sf::Event& event)
                    {
                        // Iterate from top to bottom, stop as soon as handleEvent() returns false
                        for (auto itr = mStack.rbegin(); itr != mStack.rend(); ++itr)
                        {
                            if (!(*itr)->handleEvent(event))
                                break;
                        }

                        applyPendingChanges();
                    }

                    The author has updated the code of the book and has placed them in his GitHub repository at https://github.com/LaurentGomila/SFML-Game-Development-Book.

                    Please refer to it for updated code.

                    Sample chapters

                    You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                    Frequently bought together

                    SFML Game Development +    OpenGL Development Cookbook =
                    50% Off
                    the second eBook
                    Price for both: £24.65

                    Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                    What you will learn from this book

                    • Learn the basics of SFML and render an airplane to the screen.
                    • Create a game world to play in using entities and handle input from the player
                    • Make your game richer with menus, settings, and other states
                    • Implement the foundation for a GUI library
                    • Populate the world with enemies and let them interact
                    • Load resources like textures from the hard drive and learn about resource management
                    • Animate the game object, build a particle system and look behind the scenes of rendering
                    • Add music and sound effects to your game to create an immersive gaming experience
                    • Implement multiplayer over a network to indulge in gameplay over the Internet

                    In Detail

                    Game development comprises the combination of many different aspects such as game logics, graphics, audio, user input, physics and much more. SFML is an Open Source C++ library designed to make game development more accessible, exposing multimedia components to the user through a simple, yet powerful interface.

                    If you are a C++ programmer with a stack of ideas in your head and seeking a platform for implementation, your search ends here.

                    Starting with nothing more than a blank screen, SFML Game Development will provide you with all the guidance you need to create your first fully featured 2D game using SFML 2.0. By the end, you'll have learned the basic principles of game development, including advanced topics such as how to network your game, how to utilize particle systems and much more.

                    SFML Game Development starts with an overview of windows, graphics, and user inputs. After this brief introduction, you will start to get to grips with SFML by building up a world of different game objects, and implementing more and more gameplay features. Eventually, you’ll be handling advanced visual effects, audio effects and network programming like an old pro. New concepts are discussed, while the code steadily develops.

                    SFML Game Development will get you started with animations, particle effects and shaders. As well as these fundamental game aspects, we’re also covering network programming to the extent where you’ll be able to support the game running from two different machines. The most important part, the gameplay implementation with enemies and missiles, will make up the core of our top-scrolling airplane shoot' em-up game!

                    You will learn everything you need in SFML Game Development in order to start with game development and come closer to creating your own game.

                    Approach

                    SFML Game Development is a fast-paced, step-by-step guide, providing you with all the knowledge and tools you need to create your first game using SFML 2.0

                    Who this book is for

                    SFML Game Development addresses ambitious C++ programmers who want to develop their own game. If you have plenty of ideas for an awesome and unique game, but don’t know how to start implementing them, then this book is for you. The book assumes no knowledge about SFML or game development, but a solid understanding of C++ is required.

                    Code Download and Errata
                    Packt Anytime, Anywhere
                    Register Books
                    Print Upgrades
                    eBook Downloads
                    Video Support
                    Contact Us
                    Awards Voting Nominations Previous Winners
                    Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                    Resources
                    Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software