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 & HelpPrograms › sliding background
Page Index Toggle Pages: 1
sliding background (Read 342 times)
sliding background
May 12th, 2006, 9:35pm
 
I'm trying to make the background constantly sliding from right to left without using background() in draw()...


Quote:
//  init
Test my_test;
Vector stack;

void setup ()
{
 size (800, 600);
 framerate (30);
 background (255);
 //
 my_test = new Test (width/2, height/2);
 stack = new Vector ();
 //
 stack.add (my_test);
}

void draw ()
{
 AbstractTest current = (AbstractTest) stack.get(0);
 
 //  translate (-current._x+width/2, 0);
 
 current.main ();
 //
 copy (0,0, width,height, -1,0, width-1,height);
}




class Test extends AbstractTest
{
 //  constr
 Test (float x, float y)
 {
   a = -1;
   _x = oldx = x;
   _y = oldy = y;
 }
 
 //  methods
 void main ()
 {
   ceta = 1.6 * sin (a);
   _x += 4 * cos (ceta);
   _y += 4 * sin (ceta);
   a += PI/180 * 1.6;
   //
   stroke (0, 255);
   line (_x, _y, oldx, oldy);
   //
   oldx = _x;
   oldy = _y;
 }
}

class AbstractTest
{
 //  properties
 float _x, _y, oldx, oldy;
 float ceta, a;
 
 AbstractTest (){}
 
 //  callbacks
 void main (){}
}


I'm actually making a copy of the stage then paste it 1 pixel further to the left every frame but once _x position of the drawing reaches width, there's no way to copy what's actually drawn outside the stage and i'm stuck on a (stupid?) problem that should be solvable by a combination of translate () and copy ()...

If anyone has already done that or knows about another way of doing it, any help very welcome ^^
Page Index Toggle Pages: 1