Last active
December 11, 2015 06:31
-
-
Save ChunChunMorning/abbc1caf1a78a4a0aa69 to your computer and use it in GitHub Desktop.
Siv3Dで簡単なアニメーションを作る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <Siv3D.hpp> | |
class Anime | |
{ | |
public: | |
Anime(const Texture& texture, int size, int frame) : | |
m_texture(texture), | |
m_size(size), | |
m_frame(frame), | |
m_index(0), | |
m_count(0) {} | |
void update() | |
{ | |
++m_count; | |
if (m_count > m_frame) | |
{ | |
m_count = 0; | |
++m_index; | |
if (m_index >= m_size) | |
{ | |
m_index = 0; | |
} | |
} | |
} | |
void draw(const Vec2& pos) const | |
{ | |
m_texture.uv(static_cast<double>(m_index) / m_size, 0.0, 1.0 / m_size, 1.0).draw(pos); | |
} | |
private: | |
Texture m_texture; | |
int m_size; | |
int m_frame; | |
int m_index; | |
int m_count; | |
}; | |
void Main() | |
{ | |
Texture texture(L"AsachunAnime.png"); | |
Anime anime(texture, 4, 10); | |
while (System::Update()) | |
{ | |
anime.update(); | |
anime.draw(Mouse::Pos()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment