1
General / Re: SFML Game Development book problem ( chapter 3 )
« on: August 23, 2014, 01:26:27 pm »
It works! Thanks a lot man
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#include "Aircraft.h"
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/RenderStates.hpp>
Textures::ID toTextureID(Aircraft::Type type){
switch(type){
case Aircraft::Eagle:
return Textures::Eagle;
case Aircraft::Raptor:
return Textures::Raptor;
}
}
Aircraft::Aircraft(Type type, const TextureHolder& textures) : mType(type), mSprite(textures.get(toTextureID(type)))
{
sf::FloatRect bounds = mSprite.getLocalBounds();
mSprite.setOrigin(bounds.width/2.f, bounds.height/2.f);
}
#include <Entity.h>
#include <SFML/Graphics/Sprite.hpp>
#include "ResourceHolder.h"
namespace Textures
{
enum ID
{
Eagle,
Raptor,
Desert,
};
}
template <typename Resource, typename Identifier>
class ResourceHolder;
typedef ResourceHolder<sf::Texture, Textures::ID> TextureHolder;
class Aircraft : public Entity
{
public:
enum Type
{
Eagle,
Raptor,
};
public:
Aircraft(Type type, const TextureHolder& textures);
virtual void drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const;
protected:
private:
Type mType;
sf::Sprite mSprite;
};