Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Game Development Book  (Read 2841 times)

0 Members and 1 Guest are viewing this topic.

clark

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML Game Development Book
« on: February 05, 2014, 09:33:46 pm »
 Hi!

http://www.packtpub.com/sfml-game-development/book

I am new to C++ And SFML but have been making games in Flash / Stage3D for several years.

This book on SFML is amazing, honestly, I have long been depressed by the likes of Entity Systems, specifically the kind of games I want to make often require many similar actors with different interactions/states/weapons etc. I have been stuck with inheritance. I know all the common problems I face but was marooned.

After a decade of books on Actionscript, no book gave an overview about how games can be well constructed and by comparison, I have never read anything quite so rich, sure the code is a tough one to follow for a newbie but the principles and ideas are lighting up my brain making me feel excited about programming again.

Does anyone know a modern c++ book?

The book has taught me more in 80 pages than I learned in 5 years!

Great job!  8) 8)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML Game Development Book
« Reply #1 on: February 05, 2014, 09:52:37 pm »
Nice to hear that the book has motivated you again! :)

For good C++ books I always link this StackOverflow thread.
The new edition of C++ Primer by Stanley Lippman, Josée Lajoie, and Barbara E. Moo is certainly a very good choice, if you're just getting into C++.
The "Effective" (Scott Meyers) and "Exceptional" (Herb Sutter) series are something you one should look at after having a basic understanding of C++.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: SFML Game Development Book
« Reply #2 on: February 05, 2014, 09:56:28 pm »
Glad you like our book! I hope you enjoy the remaining pages as much as you enjoyed the first 80. The best of luck to your endeavors, eXpl0it3r's references seem solid to me ! :)

gabrieljt

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: SFML Game Development Book
« Reply #3 on: February 13, 2014, 05:34:52 pm »
i am also reading the book and i think it is great.

i've just finished the first part of chapter 8 (texture atlases).

i feel like experimenting something now, and i want to make a TileBased game using the architecture, mechanisms and concepts provided by the book.

What i've done so far:

- created a Tile Entity, with Type corresponding to the tile in the Texture file (a simple tileset with 4 16x16 tiles: Space, Block1, Block2, None).
- initialized the TileData in the DataTable by its Type. They all refer to the same Texture::ID and each has it's own intRect.
- i've managed to create and attach a Tile to a Layer in the SceneGraph using the Table, providing the Tile::Type.
- there is also a SpaceTile Category, corresponding to the Space, Block1, Block2, None Tile Types from the same Texture File.

it works, and it seems to be well adapted to the framework, but i have the feeling it does not scale well.
i think i should build a vertex array to draw the tilemap in the Background Layer, but how am i going to access the tile data after i draw the map in the background layer?
it looks interesting to have a Tile Entity, as it can have attributes like Hitpoints, Effects, etc and interactions like collision detections (i've made a isWalkable() which returns true if mType == Space).

thanks!

-Gabriel

--- edit ---

based on this example http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php

i was able to create a TileMap class and draw it in the background with a single draw call:

TileMap.hpp
Quote
#ifndef GAME_TILEMAP_HPP
#define GAME_TILEMAP_HPP

#include <Game/SceneNode.hpp>

#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/VertexArray.hpp>


class TileMap : public SceneNode
{
   public:
                     TileMap(Category::Type category, const sf::Texture& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height);


   private:
      virtual void      draw(sf::RenderTarget& target, sf::RenderStates states) const;


   private:            
      sf::Texture         mTileset;
      sf::VertexArray      mVertices;
};

#endif // GAME_TILEMAP_HPP

TileMap.cpp
Quote
#include <Game/TileMap.hpp>

#include <SFML/Graphics/RenderTarget.hpp>


TileMap::TileMap(Category::Type category, const sf::Texture& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
: SceneNode(category)
, mTileset(tileset)
, mVertices()
{
   mVertices.setPrimitiveType(sf::Quads);
   mVertices.resize(width * height * 4);

   // populate the vertex array, with one quad per tile
   for (unsigned int i = 0; i < width; ++i)
      for (unsigned int j = 0; j < height; ++j)
      {
         // get the current tile number
         int tileNumber = tiles[i + j * width];

         // find its position in the tileset texture
         int tu = tileNumber % (tileset.getSize().x / tileSize.x);
         int tv = tileNumber / (tileset.getSize().x / tileSize.x);

         // get a pointer to the current tile's quad
         sf::Vertex* quad = &mVertices[(i + j * width) * 4];

         // define its 4 corners
         quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
         quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
         quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
         quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);

         // define its 4 texture coordinates
         quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
         quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
         quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
         quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
      }
}

void TileMap::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
   // apply the transform
   states.transform *= getTransform();

   // apply the tileset texture
   states.texture = &mTileset;

   // draw the vertex array
   target.draw(mVertices, states);
}

World::buildScene()
Quote
const int level[] =
    {
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 1, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 1, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    };

   std::unique_ptr<TileMap> tileMap(new TileMap(Category::SpaceTile, mTextures.get(Textures::ID::Tiles), sf::Vector2u(16, 16), level, 16, 8 ));
   tileMap->setPosition(mWorldBounds.left, mWorldBounds.top);
   mSceneLayers[Background]->attachChild(std::move(tileMap));

i'm thinking about removing the Texture from the Tile Entity, since it is not necessary anymore for drawing the tile, and then attach each Tile to the SceneGraph based on the level index (Tile Type).

suggestions?

screenshot attached, don't mind the Eagle x)
« Last Edit: February 13, 2014, 08:56:31 pm by gabrieljt »