BGRASpriteAnimation: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | ## Overview | |
| 2 | 2 | ||
| 3 | 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 | 4 | ||
| 5 | 5 | To use as replace of TImage just turn on the option 'AnimStatic' and you'll be able to load single images. | |
| 6 | 6 | ||
| 7 | 7 | ## Beginning | |
| 8 | 8 | ||
| 9 | 9 | Add a new BGRASpriteAnimation from the "BGRA Controls" component tab. | |
| 10 | 10 | ||
| 11 | 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 | 12 | ||
| 13 | 13 | This is the sprite we will use to explain how the component works: | |
| 14 | 14 | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 15 | + |  | |
| 19 | 16 | ||
| 20 | 17 | We can say the sprite dimensions are 100x500 px. It has 5 frames, so each frame is 100x100 px. | |
| 21 | 18 | ||
| 22 | 19 | 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 | 20 | ||
| 24 | 21 | Now you can run the application and see the resulting animation. | |
| 25 | 22 | ||
| 26 | 23 | ## Animation | |
| 27 | 24 | ||
| 28 | 25 | The animation properties are AnimInvert, AnimPosition, AnimRepeat, AnimRepeatLap, AnimSpeed & AnimStatic. | |
| 29 | 26 | ||
| 30 | 27 | **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 | 28 | ||
| 32 | 29 | **AnimPosition:** The position of the frame in the animation. | |
| 33 | 30 | ||
| 34 | 31 | **AnimRepeat:** The number of times the animation will be played. Set 0 for infinite. | |
| 35 | 32 | ||
| 36 | 33 | **AnimRepeatLap:** The number of times the animation was played. If it reaches the value of AnimRepeat the animation will stop. | |
| 37 | 34 | ||
| 38 | 35 | **AnimSpeed:** The speed in milliseconds between frames. | |
| 39 | 36 | ||
| 40 | 37 | **AnimStatic:** Use to start & stop the animation. | |
| 41 | 38 | ||
| 42 | 39 | ## Sprite | |
| 43 | 40 | ||
| 44 | 41 | The sprite properties are Sprite, SpriteCount, SpriteFillOpacity, SpriteFlipMode, SpriteKeyColor, SpriteResampleFilter, SpriteResampleMode, SpriteRotation. | |
| 45 | 42 | ||
| 46 | 43 | **Sprite:** A bitmap that contains all the frames of the animation. | |
| 47 | 44 | ||
| 48 | 45 | **SpriteCount:** A number that indicates the amount of frames of the sprite. | |
| 49 | 46 | ||
| 50 | 47 | The following properties are sprite modifications. | |
| 51 | 48 | ||
| 52 | 49 | **SpriteFillOpacity:** The amount of opacity from 0 to 255. | |
| 53 | 50 | ||
| 54 | 51 | **SpriteFlipMode:** Flip none, horizontal, vertical or both. | |
| 55 | 52 | ||
| 56 | 53 | **SpriteKeyColor:** The color that will be replaced with transparency. | |
| 57 | 54 | ||
| 58 | 55 | **SpriteResampleFilter:** The filter that will be used on resizing. | |
| 59 | 56 | ||
| 60 | 57 | **SpriteResampleMode:** If you choose FineResample the selected resample filter will be used. | |
| 61 | 58 | ||
| 62 | 59 | **SpriteRotation:** Rotation none, clockwise, counterclockwise. | |
| 63 | 60 | ||
| 64 | 61 | ## Events | |
| 65 | 62 | ||
| 66 | 63 | OnRedrawBefore, OnRedrawAfter, OnPositionChanging, OnPositionChanged, OnLapChanging, OnLapChanged in that order. | |
| 67 | 64 | ||
| 68 | 65 | The following events are specific to sprites. | |
| 69 | 66 | ||
| 70 | 67 | **OnRedrawBefore:** This fires before applying the sprite modifications. | |
| 71 | 68 | ||
| 72 | 69 | **OnRedrawAfter:** This fires after applying the sprite modifications, but before applying resample. | |
| 73 | 70 | ||
| 74 | 71 | The following events are specific to animation. | |
| 75 | 72 | ||
| 76 | 73 | **OnPositionChanging:** This fires before the animation changes the AnimPosition value. | |
| 77 | 74 | ||
| 78 | 75 | **OnPositionChanged:** This fires when the AnimPosition value has changed (by the animation or by the user). | |
| 79 | 76 | ||
| 80 | 77 | **OnLapChanging:** This fires before the animation changes the AnimRepeatLap value. | |
| 81 | 78 | ||
| 82 | 79 | **OnLapChanged:** This fires when the AnimRepeatLap value has changed (by the animation or by the user). | |
| 83 | 80 | ||
| 84 | 81 | ## How to Create Sprites? | |
| 85 | 82 | ||
| 86 | 83 | 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 | 84 | ||
| 88 | 85 | ## How to load images with mutiple rows? | |
| 89 | 86 | ||
| 90 | 87 | Check [this forum post](https://forum.lazarus.freepascal.org/index.php/topic,49164.msg355639.html#msg355639) project attachment. | |
| 91 | 88 | ||
| 92 | 89 | --- | |
| 93 | 90 | *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 | 91 | Category: BGRAControls | |
| 95 | 92 | Category: Components | |
| 96 | 93 | Category: Graphics |
