initial commit
This commit is contained in:
6
test/makefile
Normal file
6
test/makefile
Normal file
@@ -0,0 +1,6 @@
|
||||
test.out: test.cpp ../animatedsprite.cpp
|
||||
g++ $^ -lsfml-graphics -lsfml-window -lsfml-system -o $@
|
||||
|
||||
.PHONY: check
|
||||
check: test.out
|
||||
./test.out
|
||||
105
test/test.cpp
Normal file
105
test/test.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include "../animatedsprite.hpp"
|
||||
#include <cstdio>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "AnimatedSprite Test");
|
||||
window.setVerticalSyncEnabled(true);
|
||||
|
||||
sf::Texture texture;
|
||||
if(!texture.loadFromFile("test.png"))
|
||||
{
|
||||
std::puts("Failed to load <test.png> texture.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto const animations = Animation::LoadFromFile("testanimations.txt");
|
||||
if(animations.size() == 0)
|
||||
{
|
||||
std::puts("Test animations definition file was empty or read incorrectly.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Animation::Sprite sprite(animations, "default", texture);
|
||||
std::puts("Use the numerical keys to cycle through animations (1-7)");
|
||||
|
||||
sf::Clock sfclock;
|
||||
bool good = true;
|
||||
while(good)
|
||||
{
|
||||
sf::Event e;
|
||||
while(window.pollEvent(e))
|
||||
{
|
||||
switch(e.type)
|
||||
{
|
||||
case sf::Event::Closed:
|
||||
good = false;
|
||||
break;
|
||||
|
||||
case sf::Event::KeyReleased:
|
||||
switch(e.key.code)
|
||||
{
|
||||
case sf::Keyboard::Escape:
|
||||
good = false;
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Up:
|
||||
sprite.SetHorizontalFlip(!sprite.IsFlippedHorizontally());
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Down:
|
||||
sprite.SetVerticalFlip(!sprite.IsFlippedVertically());
|
||||
break;
|
||||
|
||||
case sf::Keyboard::R:
|
||||
sprite.ResetAnimation();
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Num1:
|
||||
sprite.SetAnimation("default");
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Num2:
|
||||
sprite.SetAnimation("default-reverse");
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Num3:
|
||||
sprite.SetAnimation("default-fast");
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Num4:
|
||||
sprite.SetAnimation("carousel");
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Num5:
|
||||
sprite.SetAnimation("carousel-margin");
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Num6:
|
||||
sprite.SetAnimation("carousel-reverse");
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Num7:
|
||||
sprite.SetAnimation("carousel-bounce");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sprite.Update(sfclock.restart());
|
||||
|
||||
window.clear();
|
||||
window.draw(sprite);
|
||||
window.display();
|
||||
}
|
||||
|
||||
window.close();
|
||||
return 0;
|
||||
}
|
||||
BIN
test/test.png
Normal file
BIN
test/test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 289 B |
73
test/testanimations.txt
Normal file
73
test/testanimations.txt
Normal file
@@ -0,0 +1,73 @@
|
||||
# ALL NUMBERS ARE >= 0 !!!
|
||||
# animation name
|
||||
# frame-origin x y
|
||||
# frame-size x y
|
||||
# frame-step x y
|
||||
# frame-margin x y
|
||||
# frame-count n
|
||||
# frame-time n
|
||||
# reverse
|
||||
# loop
|
||||
# bounce
|
||||
|
||||
animation default
|
||||
frame-origin 0 15
|
||||
frame-size 16 32
|
||||
frame-step 16 0
|
||||
frame-margin 0 0
|
||||
frame-count 4
|
||||
frame-time 32
|
||||
loop
|
||||
|
||||
animation default-reverse
|
||||
frame-origin 0 15
|
||||
frame-size 16 32
|
||||
frame-step 16 0
|
||||
frame-margin 0 0
|
||||
frame-count 4
|
||||
frame-time 32
|
||||
loop
|
||||
reverse
|
||||
|
||||
animation default-fast
|
||||
frame-origin 0 15
|
||||
frame-size 16 32
|
||||
frame-step 16 0
|
||||
frame-margin 0 0
|
||||
frame-count 4
|
||||
frame-time 16
|
||||
loop
|
||||
|
||||
animation carousel
|
||||
frame-origin 0 15
|
||||
frame-size 16 32
|
||||
frame-step 2 0
|
||||
frame-margin 0 0
|
||||
frame-count 25
|
||||
frame-time 16
|
||||
|
||||
animation carousel-reverse
|
||||
frame-origin 0 15
|
||||
frame-size 16 32
|
||||
frame-step 2 0
|
||||
frame-margin 0 0
|
||||
frame-count 25
|
||||
frame-time 16
|
||||
reverse
|
||||
|
||||
animation carousel-margin
|
||||
frame-origin 0 15
|
||||
frame-size 16 32
|
||||
frame-step 1 0
|
||||
frame-margin 1 0
|
||||
frame-count 25
|
||||
frame-time 16
|
||||
|
||||
animation carousel-bounce
|
||||
frame-origin 0 15
|
||||
frame-size 16 32
|
||||
frame-step 2 0
|
||||
frame-margin 0 0
|
||||
frame-count 25
|
||||
frame-time 32
|
||||
bounce
|
||||
Reference in New Issue
Block a user