Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : MMBasic 44b6 Sprite Copy Bug
Author | Message | ||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
Greetings. This is quite vexing, especially given how well Nick's just written sprite demonstration program appears to work. The attached zip shows the strange sprite copy behaviour I'm getting. (Using MMBasic v4.4, beta 6 of course) The bug seems to be in how sprites with transparent pixels are copied. It sort of looks like the copied image is being AND'ed with the pre-existing image. My short code sample attempts to show a red wagon with 2 turning wheels. The right wheel is animated by showing the sprites in sequence. The left wheel copies the same sprites (in sequence) to an otherwise unused sprite. The visual effect depends what that unused sprite is. As demo'd, if the sprite is a copy of the first animation image, a 'twinkling' spoke effect occurs. If you change the code to use sprite #10, which is entirely transparent pixels, as the working sprite, no wheel at all appears. (Change line 13 to w=10 to test this.) As an aside, COPY SPRITE 1 TO 1 generates an error. A bit of an illogical statement in the first place, but perhaps it should be allowed. Visit Vegipete's *Mite Library for cool programs. |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
Strange. There is no need to turn off the sprite before the copy nor to turn it back on after. The copy command does that internally for you. I took those lines out and it still doesn't work though Geoff? Nick |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
The SPRITE OFF / ON commands are not for the sprite being copied. They are for the sequentially animated sprites. Visit Vegipete's *Mite Library for cool programs. |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
You need to turn on the sprites you want to actually display but after that, you only need to copy from a "buffer" sprite to these displayed sprites and MMBASIC should do the act of turning it off, copying the sprite data, then turning on the sprite again... all in 1 swift operation to reduce the flicker. It has me puzzled because I had no problems with my demo. I tried changing your code so that sprites 10 and 11 are the displayed sprites and that it copied from sprites 1 to 8 into these displayed sprites (10,11), but still no joy. Could be a bug? I also use SPRITE MOVE in my demo. Maybe add that in and see if is any different. Nick |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
SPRITE MOVE had no effect - same problem. Note that my test code demonstrates two animation methods. The right wheel is animated the old way, before the COPY command existed. The 8 animation frames are displayed one sprite at a time - hence the SPRITE ON/OFF commands. The left wheel attempts to use the new SPRITE COPY method - turn on the desired (perhaps blank) sprite once at the start, outside the loop, then just copy the desired animation frame to that sprite. So the right wheel displays sprite number 1 - 8 in a repeating sequence and works fine. The left wheel displays only sprite 9, which is updated by copying sprite 1 - 8 in the same sequence, but does not display properly Visit Vegipete's *Mite Library for cool programs. |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
Ah! I thought it was a bit strange. Doesn't explain why SPRITE COPY isn't working though. I'll try some experiments once I can get back onto my Maximite. In the meantime, hopefully Geoff can chime in. Nick |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
I've used your sprite file to create a simple test program... Cls Mode 3 Sprite Load "WHEEL.SPR" Sprite copy 1 To 10 Sprite on 10,130,100 LABEL1: For x=0 To 400 Sprite move 10,x,200 Next GoTo LABEL1 All it does is clear screen, setup video mode, load WHEEL.SPR sprites. I'm turning on sprite 10 which is blank but prior, I am copying sprite 1 to 10 to give it something to display (#1 contains a wheel graphic). The loop that follows merely moves that sprite across the screen without animation. This does not work for some reason. It's as if the sprite copy 1 to 10 is doing nothing at all. If I change the moving sprite 10 to use sprite 1, the wheel is seen moving across the screen. Very weird. Nick |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
That's what I was finding. But it gets stranger. As you saw, if you move sprite 1 across the screen, it works. But if you SPRITE COPY 2 TO 1 and then move sprite 1 across the screen, you will see why it sort of looks to me like the copy is being AND'ed with the pre-existing contents of the sprite. You PACMAN ghost sprites have almost no transparent pixels. Perhaps that is why they seem to work so nicely. Visit Vegipete's *Mite Library for cool programs. |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
You may be onto something Pete. Try redefining your sprites to be all solid just to test the theory. Nick |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
Pete and Nick, you are right, you have uncovered a bug in B6 which does not correctly handle transparent pixels. Thanks for the great work in uncovering it. I have created a new beta that fixes that bug. It can be downloaded from: http://geoffg.net/Downloads/Maximite/MMBasic_4.4_Beta_7.zip. I have not fixed the colour registration on this version so there may be some colour fringing on white text. While I was at it I added the SPRITE PASTE command as suggested by Juri. The syntax is "SPRITE PASTE n,x,y" which causes the sprite to be drawn on screen and become a part of the screen itself. The sprite does not have to be turned on or off, the bitmap is simply copied to the screen. Geoff Geoff Graham - http://geoffg.net |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
Bloody brilliant! Nick |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
Yes indeed, bloody brilliant! Thanks Geoff, that's fantastic. /vp Visit Vegipete's *Mite Library for cool programs. |
||||
Print this page |