nomlib
Loading...
Searching...
No Matches
SpriteBatch.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_GRAPHICS_SPRITE_BATCH_HPP
30#define NOMLIB_GRAPHICS_SPRITE_BATCH_HPP
31
32#include "nomlib/config.hpp"
33#include "nomlib/math/Rect.hpp"
34#include "nomlib/graphics/sprite/Sprite.hpp"
35#include "nomlib/graphics/sprite/SpriteSheet.hpp"
36
37namespace nom {
38
39// TODO: Consider compositing from nom::Sprite instead of inheriting!
40
42class SpriteBatch: public Sprite
43{
44 public:
45 typedef SpriteBatch self_type;
46 typedef Sprite derived_class;
47
53
55 virtual ~SpriteBatch();
56
66 virtual void set_sprite_sheet(const SpriteSheet& sheet);
67
71 ObjectTypeInfo type() const override;
72
75
77 virtual int32 frame() const;
78
80 int32 frames() const;
81
93 void set_frame(int32 id);
94
101 virtual void draw(IDrawable::RenderTarget& target) const override;
102
109 virtual void draw(RenderTarget& target, real64 angle) const override;
110
111 protected:
113 IntRect offsets;
114
117
120
121 private:
127 virtual void update() override;
128};
129
130} // namespace nom
131
132#endif // include guard defined
const RenderWindow RenderTarget
Definition IDrawable.hpp:59
Run-time type information (RTTI) container class.
virtual void draw(IDrawable::RenderTarget &target) const override
Render the sprite frame.
virtual void update() override
Update the sprite for rendering with regard to positioning coordinates and target frame ID.
virtual ~SpriteBatch()
Destructor.
void set_frame(int32 id)
Set a new frame ID to render.
virtual void set_sprite_sheet(const SpriteSheet &sheet)
Use the sprite frames from an existing SpriteSheet object.
int32 frames() const
Obtain the number of frames available.
virtual int32 frame() const
Get the object's current sheet_id.
SpriteBatch * clone() const
Implements the required IDrawable::clone method.
int32 sheet_id_
The sheet's frame ID presently in use.
IntRect offsets
Source (input) coordinates – used for sprite sheet positioning.
virtual void draw(RenderTarget &target, real64 angle) const override
Render the sprite frame at an angle.
SpriteSheet sprite_sheet
Our attached sprite sheet object.
ObjectTypeInfo type() const override
Re-implements the IObject::type method.
Container class for deserialized sprite sheet data.