Transparent Sprite Persistance Problem!!

Just starting out? Need help? Post your questions and find answers here.
kinjal
User
User
Posts: 10
Joined: Thu Apr 06, 2006 8:05 pm

Transparent Sprite Persistance Problem!!

Post by kinjal »

I am writing a program to plot a graph of some values in an array. For this I have created two sprites, one contains a grid while the other is used for plotting the data points. I have used two sprites to increase the speed of plotting as I dont have to draw grid everytime the plot loop is executed.

Now the problem is that in the transparent sprite, the old poltted data persists even after the new data is plotted creating a mess on the screen. How do I clear old plotted data?

Here is my code

Code: Select all

Procedure DisplayData()
  Define x.w
  Define old_y1.w, new_y1.w
  Define old_y2.w, new_y2.w
  Define new_sprite.l  

  StartDrawing(SpriteOutput(1)) ;Starts Drawing on the sprite
  Box(0,0,512,320,$000000) 
  
  old_y1 = 128
  old_y2 = 128

  DrawingMode(#PB_2DDrawing_Transparent) ; sets Text background transparent
  For x=0 To 511 
   
    new_y1 = Read_buff(x)
    new_y2 = Read_buff(x+512)
    
    LineXY(x-1, old_y1, x, new_y1,#Red)
    LineXY(x-1, old_y2, x, new_y2,#Green)
    
    old_y1 = new_y1
    old_y2 = new_y2
  Next 
  
  StopDrawing() ;Stops drawing on the sprite
  FlipBuffers() 
  DisplayTransparentSprite(1,0,0) ; display the sprite
 EndProcedure
The grid sprite is displayed once when the program starts.

Any solution?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Code: Select all

  StopDrawing() ;Stops drawing on the sprite 
  ClearScreen(#Black)
  DisplayTransparentSprite(1,0,0) ; display the sprite 
  FlipBuffers() 
EndProcedure
BERESHEIT
kinjal
User
User
Posts: 10
Joined: Thu Apr 06, 2006 8:05 pm

Post by kinjal »

NO that does not work!

If I use ClearScreen(#Black) the background sprite which displays grid becomes invisible! I dont want to redraw the grid every time I plot the points.
kinjal
User
User
Posts: 10
Joined: Thu Apr 06, 2006 8:05 pm

Post by kinjal »

No one? :(
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

kinjal wrote:NO that does not work!

If I use ClearScreen(#Black) the background sprite which displays grid becomes invisible! I dont want to redraw the grid every time I plot the points.
I think your gonna have to redraw the grid each time. :wink:
--Kale

Image
kinjal
User
User
Posts: 10
Joined: Thu Apr 06, 2006 8:05 pm

Post by kinjal »

But I guess it takes a considerable amount of time! Isn't there any other way?
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

kinjal wrote:But I guess it takes a considerable amount of time! Isn't there any other way?
Try it, if it's just one sprite then it will be very very quick.
--Kale

Image
kinjal
User
User
Posts: 10
Joined: Thu Apr 06, 2006 8:05 pm

Post by kinjal »

Can you tell me one thing...which of these two methods will be faster?

1. I draw grid and points on same sprite. Grid drawing consitst of two loops which goes from 0 to 512 in steps of 32 and draws lines which needs to be executed whenever points are plotted.

2. The other method is using 2 sprites. I draw grid on one sprite during startup then every time I plot the points I display both the sprites using DisplaySprite(....) and DisplayTransparentSprite(...) methods.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

#2 makes more sense.
BERESHEIT
Post Reply