Add sprites to sprite-test This changeset brings up the asset pipeline for sprite-test and walks through some of the methods for drawing sprites to the screen.
diff --git a/examples/sprite-test/CMakeLists.txt b/examples/sprite-test/CMakeLists.txt index 88ae77a..ea2de68 100644 --- a/examples/sprite-test/CMakeLists.txt +++ b/examples/sprite-test/CMakeLists.txt
@@ -2,3 +2,4 @@ project (sprite-test) include (../../32blit.cmake) blit_executable (sprite-test sprite-test.cpp) +blit_assets_yaml(sprite-test assets.yml)
diff --git a/examples/sprite-test/assets.yml b/examples/sprite-test/assets.yml new file mode 100644 index 0000000..f0b7432 --- /dev/null +++ b/examples/sprite-test/assets.yml
@@ -0,0 +1,3 @@ +assets.cpp: + ../../assets/s4m_ur4i-dingbads.png: + name: asset_dingbads
diff --git a/examples/sprite-test/sprite-test.cpp b/examples/sprite-test/sprite-test.cpp index 6b0f7d7..6b545ee 100644 --- a/examples/sprite-test/sprite-test.cpp +++ b/examples/sprite-test/sprite-test.cpp
@@ -4,6 +4,7 @@ #include <cstdlib> #include "sprite-test.hpp" +#include "assets.hpp" using namespace blit; @@ -12,6 +13,9 @@ /* setup */ void init() { + // You gotta load those tasty sprites first + // "asset_dingbads" is the asset name defined in assets.yml + screen.sprites = SpriteSheet::load(asset_dingbads); } int tick_count = 0; @@ -22,11 +26,45 @@ screen.alpha = 255; screen.mask = nullptr; + // draw grid + screen.alpha = 255; + screen.pen = Pen(255, 255, 255); + screen.rectangle(Rect(0, 0, 320, 14)); + + screen.text("Apple", minimal_font, Point(5, 20)); + screen.text("Skull", minimal_font, Point(5, 40)); + screen.text("Flowers", minimal_font, Point(5, 60)); + + screen.pen = Pen(0, 0, 0); + screen.text("Sprite demo", minimal_font, Point(5, 4)); + uint32_t ms_start = now(); + // Draw a sprite using its numerical index into the sprite sheet + // Treats the sprite sheet as a grid of 8x8 sprites numbered from 0 to 63 + // In this case sprite number 1 is the second sprite from the top row. + // It should be an apple! Munch! + screen.sprite(1, Point(60, 20)); + + // Draw a sprite using its X/Y position from the sprite sheet + // Treats the sprite sheet as a grid of 8x8 sprites + // numbered 0 to 15 across and 0 to 15 down! + // In this case we draw the sprite from: + // The 10th position across (0 based, remember!) + // The 3rd position down. + // It should be a skull! Yarr! + screen.sprite(Point(9, 2), Point(60, 40)); + + // Draw a group of sprites starting from an X/Y position, with a width/height + // Treats the sprite sheet a grid of 8x8 sprites and selects a group of them defined by a Rect(x, y, w, h) + // The width and height are measured in sprites. + // In this case we draw three sprites from the 6th column on the 12th row. + // It should be a row of flowers! Awww! + screen.sprite(Rect(5, 11, 3, 1), Point(60, 60)); uint32_t ms_end = now(); + // draw FPS meter screen.alpha = 255; screen.pen = Pen(255, 255, 255, 100);