BGRASpriteAnimation: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: BGRASpriteAnimation
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Overview | |
| 2 | + | ||
| 3 | + | [[BGRASpriteAnimation]] is a graphic control developed with the [[BGRABitmap]] library. It is part of the [[BGRAControls]] package. This control is usefull to create animations from bitmaps. | |
| 4 | + | ||
| 5 | + | To use as replace of TImage just turn on the option 'AnimStatic' and you'll be able to load single images. | |
| 6 | + | ||
| 7 | + | ## Beginning | |
| 8 | + | ||
| 9 | + | Add a new BGRASpriteAnimation from the "BGRA Controls" component tab. | |
| 10 | + | ||
| 11 | + | The next step is to load a "sprite". A sprite is a bitmap that contains all the frames of an animation. To load a sprite select "BGRASpriteAnimation1". In the Object Inspector click on the property "Sprite (TBitmap)\[...\]". Load the sprite the same way as you load any other bitmap. | |
| 12 | + | ||
| 13 | + | This is the sprite we will use to explain how the component works: | |
| 14 | + | ||
| 15 | + | <figure> | |
| 16 | + | <img src="bgraspriteanimation_main_sprite.png" title="bgraspriteanimation_main_sprite.png" /> | |
| 17 | + | <figcaption>bgraspriteanimation_main_sprite.png</figcaption> | |
| 18 | + | </figure> | |
| 19 | + | ||
| 20 | + | We can say the sprite dimensions are 100x500 px. It has 5 frames, so each frame is 100x100 px. | |
| 21 | + | ||
| 22 | + | The next step is to tell the component that the sprite has 5 frames. To set the number of frames in the Object Inspector click on the property "SpriteCount" and set the value to 5. | |
| 23 | + | ||
| 24 | + | Now you can run the application and see the resulting animation. | |
| 25 | + | ||
| 26 | + | ## Animation | |
| 27 | + | ||
| 28 | + | The animation properties are AnimInvert, AnimPosition, AnimRepeat, AnimRepeatLap, AnimSpeed & AnimStatic. | |
| 29 | + | ||
| 30 | + | **AnimInvert:** By default the animation is played from AnimPosition to SpriteCount. If you set AnimInvert to True the animation will be played inversely, that is from the last frame to the first. | |
| 31 | + | ||
| 32 | + | **AnimPosition:** The position of the frame in the animation. | |
| 33 | + | ||
| 34 | + | **AnimRepeat:** The number of times the animation will be played. Set 0 for infinite. | |
| 35 | + | ||
| 36 | + | **AnimRepeatLap:** The number of times the animation was played. If it reaches the value of AnimRepeat the animation will stop. | |
| 37 | + | ||
| 38 | + | **AnimSpeed:** The speed in milliseconds between frames. | |
| 39 | + | ||
| 40 | + | **AnimStatic:** Use to start & stop the animation. | |
| 41 | + | ||
| 42 | + | ## Sprite | |
| 43 | + | ||
| 44 | + | The sprite properties are Sprite, SpriteCount, SpriteFillOpacity, SpriteFlipMode, SpriteKeyColor, SpriteResampleFilter, SpriteResampleMode, SpriteRotation. | |
| 45 | + | ||
| 46 | + | **Sprite:** A bitmap that contains all the frames of the animation. | |
| 47 | + | ||
| 48 | + | **SpriteCount:** A number that indicates the amount of frames of the sprite. | |
| 49 | + | ||
| 50 | + | The following properties are sprite modifications. | |
| 51 | + | ||
| 52 | + | **SpriteFillOpacity:** The amount of opacity from 0 to 255. | |
| 53 | + | ||
| 54 | + | **SpriteFlipMode:** Flip none, horizontal, vertical or both. | |
| 55 | + | ||
| 56 | + | **SpriteKeyColor:** The color that will be replaced with transparency. | |
| 57 | + | ||
| 58 | + | **SpriteResampleFilter:** The filter that will be used on resizing. | |
| 59 | + | ||
| 60 | + | **SpriteResampleMode:** If you choose FineResample the selected resample filter will be used. | |
| 61 | + | ||
| 62 | + | **SpriteRotation:** Rotation none, clockwise, counterclockwise. | |
| 63 | + | ||
| 64 | + | ## Events | |
| 65 | + | ||
| 66 | + | OnRedrawBefore, OnRedrawAfter, OnPositionChanging, OnPositionChanged, OnLapChanging, OnLapChanged in that order. | |
| 67 | + | ||
| 68 | + | The following events are specific to sprites. | |
| 69 | + | ||
| 70 | + | **OnRedrawBefore:** This fires before applying the sprite modifications. | |
| 71 | + | ||
| 72 | + | **OnRedrawAfter:** This fires after applying the sprite modifications, but before applying resample. | |
| 73 | + | ||
| 74 | + | The following events are specific to animation. | |
| 75 | + | ||
| 76 | + | **OnPositionChanging:** This fires before the animation changes the AnimPosition value. | |
| 77 | + | ||
| 78 | + | **OnPositionChanged:** This fires when the AnimPosition value has changed (by the animation or by the user). | |
| 79 | + | ||
| 80 | + | **OnLapChanging:** This fires before the animation changes the AnimRepeatLap value. | |
| 81 | + | ||
| 82 | + | **OnLapChanged:** This fires when the AnimRepeatLap value has changed (by the animation or by the user). | |
| 83 | + | ||
| 84 | + | ## How to Create Sprites? | |
| 85 | + | ||
| 86 | + | Most Graphics software (Gimp, Photoshop) can create Animations as Image Sequences. In Windows you can use IrfanView's (Freeware) panoramamode to Join these Images into a sprite. (Image\> Create Panorama Image…) | |
| 87 | + | ||
| 88 | + | ## How to load images with mutiple rows? | |
| 89 | + | ||
| 90 | + | Check [this forum post](https://forum.lazarus.freepascal.org/index.php/topic,49164.msg355639.html#msg355639) project attachment. | |
| 91 | + | ||
| 92 | + | --- | |
| 93 | + | *From the Free Pascal wiki, page "BGRASpriteAnimation", as it stood on 2020-04-03 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 94 | + | Category: BGRAControls | |
| 95 | + | Category: Components | |
| 96 | + | Category: Graphics |
