First, due to a bug I missed, non-looping sprite animations currently crash in 1.4. So if you're using 1.4 and not latest SVN you'll need to edit CGUISpriteBank.cpp and change line 106 to-
Code: Select all
frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f;
Finally, open the user interface example and paste the following code somewhere after "IGUIEnvironment* env = "
Code: Select all
IGUISpriteBank* sprites = env->getSkin()->getSpriteBank();
// load and add the texture to the bank
driver->makeColorKeyTexture(driver->getTexture("../../sprite.png"), position2di(0,0));
sprites->addTexture(driver->getTexture("../../sprite.png"));
u32 textureIndex = sprites->getTextureCount() - 1;
// now lets get the sprite bank's rectangles and add some for our animation
core::array<core::rect<s32> >& rectangles = sprites->getPositions();
u32 firstRect = rectangles.size();
// remember that rectangles are not in pixels, they enclose pixels!
// to draw a rectangle around the pixel at 0,0, it would rect<s32>(0,0, 1,1)
rectangles.push_back(rect<s32>(0,1, 8,8));
rectangles.push_back(rect<s32>(9,1, 16,8));
rectangles.push_back(rect<s32>(0,9, 5,16));
rectangles.push_back(rect<s32>(6,9, 10,16));
rectangles.push_back(rect<s32>(11,9, 14,16));
// now we make a sprite..
SGUISprite sprite;
sprite.frameTime = 30;
// add some frames of animation.
s32 n;
for (n=0; n < 5; ++n)
{
// animate forward
SGUISpriteFrame frame;
frame.rectNumber = firstRect + n;
frame.textureNumber = textureIndex;
// add this frame
sprite.Frames.push_back(frame);
}
for (n=4; n > -1; --n)
{
// and now in reverse
SGUISpriteFrame frame;
frame.rectNumber = firstRect + n;
frame.textureNumber = textureIndex;
// add this frame
sprite.Frames.push_back(frame);
}
// add the sprite
u32 spriteIndex = sprites->getSprites().size();
sprites->getSprites().push_back(sprite);
// now let's use this as the X window button
env->getSkin()->setIcon(EGDI_WINDOW_CLOSE, spriteIndex);