BBC BASIC for Windows
Programming >> Graphics and Games >> Static background vs changing foreground
http://bb4w.conforums.com/index.cgi?board=graphics&action=display&num=1416311922

Static background vs changing foreground
Post by 5against4 on Nov 18th, 2014, 10:58am

Apologies if this is a very straightforward thing to do, but i'd like a program to do various draw/plot processes intially, which then remain static in the background while other changing processes are drawn on top.

Essentially i have a roaming target-like cursor moving over various pre-drawn circles - screenshot here.

Is this possible to do simply? At present it's re-drawing the background each time but i feel sure there must be a more efficient way of doing this.

Any help very much appreciated! smiley
Re: Static background vs changing foreground
Post by rtr2 on Nov 18th, 2014, 1:13pm

on Nov 18th, 2014, 10:58am, 5against4 wrote:
Essentially i have a roaming target-like cursor moving over various pre-drawn circles

As is so often the case, there are several ways in which you might go about this.

Probably the most conventional way is to draw the 'cursor' in exclusive-or plotting mode (GCOL 3 or GCOL 4), so you can 'undo' the plotting operation simply by repeating it. So whenever you need to move the cursor/target you would first re-plot it at its previous position (hence erasing it) and then plot it at its new position.

Another approach would be to create your cursor/target as a sprite, and then move it around using the capabilities in SPRITELIB. That probably gives you the greatest flexibility in size and colour.

Yet another possibility would be to change the Windows mouse pointer to the shape you need (if one of the pre-defined shapes isn't suitable, you can create your own) then let Windows do the work for you. You are restricted to a maximum size of 32 x 32 pixels, I think.

Does one of these solutions meet your requirements?

Richard.
Re: Static background vs changing foreground
Post by 5against4 on Nov 20th, 2014, 7:09pm

Thanks for the reply Richard.

on Nov 18th, 2014, 1:13pm, g4bau wrote:
Probably the most conventional way is to draw the 'cursor' in exclusive-or plotting mode (GCOL 3 or GCOL 4), so you can 'undo' the plotting operation simply by repeating it. So whenever you need to move the cursor/target you would first re-plot it at its previous position (hence erasing it) and then plot it at its new position.

This is what i'm doing at the moment, but this necessitates re-drawing the background elements as they're also erased when the cursor overlaps them.

on Nov 18th, 2014, 1:13pm, g4bau wrote:
Another approach would be to create your cursor/target as a sprite, and then move it around using the capabilities in SPRITELIB. That probably gives you the greatest flexibility in size and colour.

Yet another possibility would be to change the Windows mouse pointer to the shape you need (if one of the pre-defined shapes isn't suitable, you can create your own) then let Windows do the work for you. You are restricted to a maximum size of 32 x 32 pixels, I think.

Both of these sound interesting - would they obviate the need to re-draw the background? If you could elaborate a bit more i'd be grateful - thanks!
Re: Static background vs changing foreground
Post by rtr2 on Nov 20th, 2014, 8:48pm

on Nov 20th, 2014, 7:09pm, 5against4 wrote:
This is what i'm doing at the moment, but this necessitates re-drawing the background elements

No, exclusive-or plotting does not necessitate re-drawing the background; you must be doing it incorrectly. Here is a trivial demonstration program (use the cursor keys to move):

Code:
      MODE 8
      REM Draw a 'random' background:
      FOR N% = 1 TO 100
        GCOL RND(15)
        CIRCLE FILL RND(1280), RND(1024), RND(300)
      NEXT
      REM Switch to 'exclusive-or' plotting:
      GCOL 4,0
      REM Move a 'cursor' around without destroying the background:
      X% = 500
      Y% = 500
      VDU 23,23,2;0;0;0;
      REPEAT
        PROCcursor(X%,Y%)
        K% = INKEY(10)
        PROCcursor(X%,Y%)
        CASE K% OF
          WHEN 136: X% -= 4
          WHEN 137: X% += 4
          WHEN 138: Y% -= 4
          WHEN 139: Y% += 4
        ENDCASE
      UNTIL FALSE
      END

      DEF PROCcursor(X%,Y%)
      LINE X%,Y%+50,X%,Y%-50
      LINE X%-50,Y%,X%+50,Y%
      CIRCLE X%,Y%,30
      ENDPROC 

Quote:
Both of these sound interesting - would they obviate the need to re-draw the background?

Of course. All three methods I suggested achieve that - I thought that was the whole point.

Richard.
Re: Static background vs changing foreground
Post by 5against4 on Dec 9th, 2014, 09:14am

Apologies for the delay replying - i've been away.

That exclusive-or plotting approach worked perfectly - thank you ever so much!