ButtonComponent is used for example to create a button. As you can see, you can give it a function or an anction to do when he's clicked and that's useful for a button.
ControllableComponent
class ControllableComponent {
public:
ControllableComponent(std::initializer_list<sf::Keyboard::Key> controls);
const std::vector<sf::Keyboard::Key> &getControls() const;
int getEvent() const;
void setEvent(int event);
private:
std::vector<sf::Keyboard::Key> _controls;
int _event = 0;
};
You will use this class to set your entity position.
The method ControllableComponent() present in this class will be useful to set which keys you want to control your entity. Ex: For our player, we set key up, key down, key right, key left.
The method getControls() will be useful to get all the keys registered with your entity.
Ex: If user press key down, we will be loop on getControls function and check if the key has been pressed (if yes, player will move, otherwise player will not move).
The method getEvent() can be use to get actual events.
The method setEvent can set actuel event into an int.
LoadingBarComponent is an usefull class to create flexible bar, like a life bar for example.
The method calculate automatically set the width of your bar using its parameter float currentWidth.
MusicComponent
class MusicComponent {
public:
MusicComponent(const std::string &musicPath, float volume = 100.0f, bool loop = false): _musicPath(musicPath);
int playMusic();
int pauseMusic();
int stopmusic();
void setLoop(bool loop);
void setVolume(float volume);
sf::SoundSource::Status getStatus();
float getVolume() const;
private:
std::string _musicPath;
std::shared_ptr<sf::Music> _music;
};
MusicComponent as you may guess, is the component that you will use to handle the music behavior in your game.
Its simply an encapsulation of the sfml sf::Music class.
If you want to move an entity from left to the right automatically (like a parallax, ex: game's background) you can use the parallax component. This class needs to the size of your sprite sheet and the speed where it will move.
The ParticuleComponent can be use to create particule with rectangle using sf::IntRect from SFML graphic library.
You can either set the color of the particule and the duration.
RectangleShapeComponent is the component that we use for the player life we can set which Rect that we want depending on the player life. You will find a lot of methods that are useful to handle the display of one of your entities.
This component can be use if your entity does'nt fit as you want. Using this component, you can fit your entity as you want.
The first part of this class is useful to set the scale you want for your entity,
The second one will be useful if you want to get the scale set to an entity at his creation.
SoundComponent
class SoundComponent {
public:
SoundComponent(const std::string &soundPath, float volume = 100.0f, bool play = false): _soundPath(soundPath);
int playSound();
int pauseSound();
int stopSound();
void setVolume(float volume);
sf::SoundSource::Status getStatus() const;
float getVolume() const;
private:
std::string _soundPath;
std::shared_ptr<sf::SoundBuffer> _soundBuffer;
std::shared_ptr<sf::Sound> _sound;
};
SoundComponent is the component that we use for the sound created when the player shoots for example. A sound is different than a music because a sound will be shorter than a music. You will use that if you want a short sonore effect when an action has been done for example.
SpriteComponent
This component is use to store the entity's sprite
TextComponent is the component that you have to use if you wantt to write something on your screen. In this one, you can adjust what you want like position, size, color, content or things like that for your text. You're free to write what you wan and above all how you want.
TextureRectComponent
class TextureRectComponent {
public:
TextureRectComponent(int left, int top, int totalWidth, int height, int numFrames, float frameDelay)
sf::IntRect &getTextureRect()
const sf::IntRect &getTextureRect() const
sf::IntRect _textureRect
int _frameWidth
int _numFrames
float _frameDelay
float _timeSinceLastFrameChange
};
TextureRect component is useful to set your sprite correctly. To works normally, it needs to get the right informations about the position of your differents things in your sprite's file.
This component is very useful to set the velocity to an entity. It works with de MoveComponent component. To works correctly, it needs to get two mains informations : direction &. speed.
Once it's setted, your entity will move depending on params you gave.