We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › overwriting background
Page Index Toggle Pages: 1
overwriting background (Read 776 times)
overwriting background
Sep 30th, 2009, 9:44am
 
Hey,

I'm working on a program that, when the user hits different keys (jkdf), a bezier curve is drawn on the screen.  After the curve is on the screen, the user can then reposition the curve (size, position). However, I'm having difficult with the initiation of drawing the curves.  For instance, if in draw() I automatically display a curve, it shows up. Otherwise, with the key clicks, it shows up for a second only to be drawn over again by the background (which is also in draw). Where in the code should I put the background?  I want it redrawn when the curve is moved, so that there isn't a trail of shadows, but I want the curves to be drawn in the first place.

Thanks!  And if this isn't clear enough, please let me know what I can do to change it.
Re: overwriting background
Reply #1 - Sep 30th, 2009, 9:50am
 
sounds like it'd be best if you turned off the auto-looping on draw(). you can do this using noLoop()

http://processing.org/reference/noLoop_.html

and draw one frame using redraw()

http://processing.org/reference/redraw_.html

put the latter in the code that handles the keypresses so that it redraws only when you've changed something.
Re: overwriting background
Reply #2 - Sep 30th, 2009, 10:23am
 
I tested out what you said to do and if fixed some things, but caused a few problems, too.  The good thing is that all the curves can now be drawn on the screen. However, when I try to drag them (I also put redraw in mousePressed() and mouseReleased() in the hopes that, when they changed, the curve would change as well) they move by 1 every time, as opposed to being able to drag them across the whole screen.  Also, because the background isn't updating, whenever I do change anything, a shadow is left behind of where the image was before.  Is there anything I can do to fix that (keeping the changes you gave me before), or should I take out the noLoop() and try something different?
Re: overwriting background
Reply #3 - Sep 30th, 2009, 10:27am
 
The only problem with noLoop(), as the OP has clearly discovered, is that it gets in the way of anything you do want to repeat in draw().  I suspect a better option would be to create a 'curve' object and when one is created add this to an array of curves; then iterate through this array and render it in the draw loop and adjust individual curve properties directly using keyboard/mouse interaction...
Re: overwriting background
Reply #4 - Sep 30th, 2009, 10:31am
 
So, in order to create this curve object, should I define a new class?  

class curve { ... etc.

Essentially, then, the makeCurve() method that I have would be transformed into a curve class with those properties--is that along the line of what you said?
Re: overwriting background
Reply #5 - Oct 1st, 2009, 1:57am
 
Yes.  You'd obviously need to give it appropriate properties, a constructor which would be called when a new curve is added and a display method.  You could also write specific methods as required for your usecase.

With a separate curve object the properties of the curve only get changed at given events, so you can simply call the curve display method in your draw loop each frame to achieve what you want.  When the properties change the curve will update in draw... and you don't disturb the flow of the draw loop...
Page Index Toggle Pages: 1