Skip to content

Instantly share code, notes, and snippets.

@ChunChunMorning
Last active December 11, 2015 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChunChunMorning/abbc1caf1a78a4a0aa69 to your computer and use it in GitHub Desktop.
Save ChunChunMorning/abbc1caf1a78a4a0aa69 to your computer and use it in GitHub Desktop.
Siv3Dで簡単なアニメーションを作る
# 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