TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrainsExpress::Graphics::ParallaxBackdrop Class Reference

#include <tbx_parallax_backdrop.h>

Inheritance diagram for TurtleBrainsExpress::Graphics::ParallaxBackdrop:
TurtleBrains::Graphics::Graphic

Public Types

enum  ScrollingType { ScrollingType::kNoScrolling, ScrollingType::kHorizontal, ScrollingType::kVertical, ScrollingType::kFullScrolling }
 

Public Member Functions

 ParallaxBackdrop (const ScrollingType &scrollingType=ScrollingType::kNoScrolling)
 
virtual ~ParallaxBackdrop (void)
 
void AddParallaxLayer (const tbCore::tbString &layerFilepath, const float parallaxMultiplier, const tbMath::Vector2 &offset=tbMath::Vector2::Zero())
 
ScrollingType GetScrollingType (void) const
 
- Public Member Functions inherited from TurtleBrains::Graphics::Graphic
 Graphic (void)
 
 Graphic (const Graphic &other)
 
virtual ~Graphic (void)
 
bool IsActive (void) const
 
void SetActive (const bool isActive)
 
void Update (const float deltaTime)
 
bool IsVisible (void) const
 
void SetVisible (const bool isVisible)
 
void Render (void) const
 
const tbMath::Vector2GetPosition (void) const
 
void SetPosition (const float x, const float y)
 
void SetPosition (const tbMath::Vector2 &position)
 
void SetOrigin (const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero())
 
void SetOrigin (const float originX, const float originY)
 
void SetOrigin (const tbMath::Vector2 &origin)
 
float GetDepth (void) const
 
void SetDepth (const float newDepth)
 
const tbMath::Vector2GetScale (void) const
 
void SetScale (const float scale)
 
void SetScale (const float scaleX, const float scaleY)
 
float GetRotation (void) const
 
void SetRotation (const float rotation)
 
void SetScroll (const float scroll)
 
void SetScroll (const float scrollX, const float scrollY)
 
bool IsRelative (void) const
 
const ColorGetColor (void) const
 
virtual void SetColor (const tbGraphics::Color &newColor)
 
virtual PixelSpace GetPixelWidth (void) const
 
virtual PixelSpace GetPixelHeight (void) const
 
float GetWidth (void) const
 
float GetHeight (void) const
 

Protected Member Functions

virtual void OnRender (void) const override
 
- Protected Member Functions inherited from TurtleBrains::Graphics::Graphic
virtual void OnUpdate (const float deltaTime)
 
virtual void ApplyTransform (void) const
 
virtual void PopTransform (void) const
 

Detailed Description

The ParallaxBackdrop object takes a collection of sprites to have a depth/parallax effect when the object moves. It supports endless Horizontal or Vertical scrolling, Omni Directional scrolling or if desired no scrolling for menu like effects.

Member Enumeration Documentation

Enumerator
kNoScrolling 

No endless scrolling for this type of backdrop.

kHorizontal 

This type of backdrop will endlessly scroll horizontally, side-to-side, as it moves.

kVertical 

This type of backdrop will endlessly scroll vertically, up-and-down, as it moves.

kFullScrolling 

This type of backdrop will endlessly scroll in any direction as it moves.

Constructor & Destructor Documentation

TurtleBrainsExpress::Graphics::ParallaxBackdrop::ParallaxBackdrop ( const ScrollingType scrollingType = ScrollingType::kNoScrolling)
explicit

Constructs an empty ParallaxBackdrop with the specified scrolling type.

Parameters
scrollingTypeThe direction of endless scrolling that the backdrop should have.
virtual TurtleBrainsExpress::Graphics::ParallaxBackdrop::~ParallaxBackdrop ( void  )
virtual

Cleans-up after the ParallaxBackdrop object and any sprite resources it used.

Member Function Documentation

void TurtleBrainsExpress::Graphics::ParallaxBackdrop::AddParallaxLayer ( const tbCore::tbString layerFilepath,
const float  parallaxMultiplier,
const tbMath::Vector2 offset = tbMath::Vector2::Zero() 
)

Add a new layer to the parallax effect for the backdrop. Each layer will perform the endless scrolling for itself adding slightly more computation time and fill-rate for graphics, although the layer will draw the minimum number of times to perform scrolling expected of the backdrop. Each time a new layer is added, it will be added in front of all previous layers.

Parameters
layerFilepathThe path of the file to load as a sprite that will be used for this layer of the backdrop, minimum size is 100x100px although smaller sprites will incur more performance overhead.
parallaxMultiplierEssentially the amount of movement the layer will have, 0 would keep the layer from moving at all, and 1 would move at the same rate of speed as the backdrop object moves.
offsetIf desired this will allow the layer to be offset positionally.
ScrollingType TurtleBrainsExpress::Graphics::ParallaxBackdrop::GetScrollingType ( void  ) const
inline

Returns the scrolling of type of the backdrop object.

virtual void TurtleBrainsExpress::Graphics::ParallaxBackdrop::OnRender ( void  ) const
overrideprotectedvirtual

Overrides OnRender() to be capable of endlessly scrolling each layer as the backdrop moves, depending on the scroll type of the backdrop object.

Implements TurtleBrains::Graphics::Graphic.