BBC Basic Sprite Question
Sascha Leidel (9754) 11 posts |
II have a small question. Can someone give me an example code? I would like to adapt a sprite to the resolution of the desktop. Desktop is e.g. 1280×600 the Sprite 1024×300. It should then be at the height of 600, width then accordingly… |
Rick Murray (539) 13850 posts |
The simplest way is to use OS_SpriteOp.
https://www.riscosopen.org/wiki/documentation/show/OS_SpriteOp Note that as you’ll be providing your own sprite area and referring to the sprite by name, you should add 256 to all of the calls, as indicated above. The linked page explains this. [ the other way is to load the sprite header into memory and pull it apart, but note that sprites don’t store a width, they record how many words the scanline takes, along with left/right wastage (to indicate how many bytes are unused on either side) and the effective width is a combination of that and the bits per pixel of the image; it’s a lot more complicated ] |
Sascha Leidel (9754) 11 posts |
Get the length of the sprite file and add four. Have you a short sample for that ? |
Chris Hall (132) 3558 posts |
A sprite area is very similar in content to a sprite file – the length of the sprite area is the first word (corresponding to the file length) then the data from the file follow. Once a sprite area is set up, you can use SpriteOp SWIs on it. An alternative approach is to embed the sprite in a Draw file and then Render the Drawfile to the screen. That will display any sprite stretched to fit the area you choose, e.g. the whole screen. Example using MakeDraw:
|
Charles Ferguson (8243) 427 posts |
https://github.com/gerph/riscos-examples/blob/master/graphics/sprites/PlotSprite%2Cfd1 covers many different ways. |
Steve Fryatt (216) 2105 posts |
The (sensible) test for P being zero at line 190 seems a little pointless1, because absent any error handling which hasn’t been included in your example, you’ll get a crash at line 180 with “Handle is either illegal or has been closed” in the event that P is zero… 1 Yes, it’s not wrong to include, because CLOSE# should never be called with a handle of zero. However, it would probably be better to do something like
and then gracefully exit if filelen% is zero at the end of it all. |
Steve Fryatt (216) 2105 posts |
Just to chuck another example into the mix, you’ll find a more Wimp oriented example of loading a sprite area here: |