Kiwano Engine
v1.3.x
Sprite.h
1
// Copyright (c) 2016-2018 Kiwano - Nomango
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to deal
5
// in the Software without restriction, including without limitation the rights
6
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
// copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
// THE SOFTWARE.
20
21
#pragma once
22
#include <kiwano/2d/Actor.h>
23
#include <kiwano/2d/SpriteFrame.h>
24
25
namespace
kiwano
26
{
27
37
class
KGE_API
Sprite
:
public
Actor
38
{
39
public
:
40
Sprite
();
41
45
Sprite
(
StringView
file_path);
46
50
Sprite
(
const
Resource
& res);
51
55
Sprite
(
RefPtr<Texture>
texture);
56
61
Sprite
(
StringView
file_path,
const
Rect
& crop_rect);
62
67
Sprite
(
const
Resource
& res,
const
Rect
& crop_rect);
68
73
Sprite
(
RefPtr<Texture>
texture,
const
Rect
& crop_rect);
74
78
Sprite
(
const
SpriteFrame
& frame);
79
80
virtual
~Sprite
();
81
85
bool
Load(
StringView
file_path);
86
90
bool
Load(
const
Resource
& res);
91
94
RefPtr<Texture>
GetTexture()
const
;
95
98
Rect
GetCropRect()
const
;
99
102
SpriteFrame
GetFrame()
const
;
103
107
void
SetCropRect(
const
Rect
& crop_rect);
108
112
void
SetFrame(
const
SpriteFrame
& frame);
113
114
void
OnRender(
RenderContext
& ctx)
override
;
115
116
protected
:
117
bool
CheckVisibility(
RenderContext
& ctx)
const override
;
118
119
private
:
120
SpriteFrame
frame_;
121
};
122
125
inline
RefPtr<Texture>
Sprite::GetTexture
()
const
126
{
127
return
frame_.
GetTexture
();
128
}
129
130
inline
Rect
Sprite::GetCropRect
()
const
131
{
132
return
frame_.
GetCropRect
();
133
}
134
135
inline
SpriteFrame
Sprite::GetFrame
()
const
136
{
137
return
frame_;
138
}
139
140
inline
void
Sprite::SetCropRect
(
const
Rect
& crop_rect)
141
{
142
frame_.
SetCropRect
(crop_rect);
143
}
144
145
}
// namespace kiwano
kiwano::Actor
角色
Definition:
Actor.h:63
kiwano::BasicStringView< char >
kiwano::RefBasePtr
引用计数智能指针
Definition:
RefBasePtr.hpp:35
kiwano::RenderContext
渲染上下文
Definition:
RenderContext.h:62
kiwano::Resource
资源
Definition:
Resource.h:41
kiwano::SpriteFrame
精灵帧
Definition:
SpriteFrame.h:34
kiwano::SpriteFrame::GetTexture
RefPtr< Texture > GetTexture() const
获取纹理
Definition:
SpriteFrame.h:131
kiwano::SpriteFrame::SetCropRect
void SetCropRect(const Rect &crop_rect)
裁剪精灵帧为矩形
Definition:
SpriteFrame.cpp:84
kiwano::SpriteFrame::GetCropRect
const Rect & GetCropRect() const
获取裁剪矩形
Definition:
SpriteFrame.h:126
kiwano::Sprite
精灵
Definition:
Sprite.h:38
kiwano::Sprite::GetCropRect
Rect GetCropRect() const
获取裁剪矩形
Definition:
Sprite.h:130
kiwano::Sprite::SetCropRect
void SetCropRect(const Rect &crop_rect)
使用矩形区域裁剪精灵
Definition:
Sprite.h:140
kiwano::Sprite::GetTexture
RefPtr< Texture > GetTexture() const
获取图像
Definition:
Sprite.h:125
kiwano::Sprite::GetFrame
SpriteFrame GetFrame() const
获取精灵帧
Definition:
Sprite.h:135
kiwano::math::RectT< float >
src
kiwano
2d
Sprite.h
制作者
1.9.4