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 › wrapping bult-in functions inside custom methods
Page Index Toggle Pages: 1
wrapping bult-in functions inside custom methods (Read 655 times)
wrapping bult-in functions inside custom methods
Sep 26th, 2005, 11:40pm
 
Hey list,

Iam trying to do wrap a mouseMoved() function inside of my move() function in my class.
This is how it goes:


int MAX = 200;
int y = 0;

Flower[] flowers = new Flower[MAX];



void setup() {
 size(200,200);
 background(0);
 color tempcolor = color(255,0,255);
 for(int i=0; i<MAX;i++) {
   flowers[i] = new Flower(100,30+y,40,50);
   y = y + 10;

 }
}



void draw() {
 for(int i=0; i<MAX;i++) {
   flowers[i].render();
   flowers[i].move();
 }
}

class Flower
{
 color fcolor;
 int xpos;
 int ypos;
 int fsize;




 Flower(color fcolor_, int xpos_, int ypos_, int fsize_) {
   fcolor = fcolor_;
   xpos = xpos_;
   ypos = ypos_;
   fsize = fsize_;
 }

 void render() {
   rectMode(CENTER) ;
   fill(fcolor);
   rect(xpos, ypos, fsize, fsize);

 }

 void move() {
   void mouseMoved() {

     xpos = xpos + 5;
     if (xpos > width) {
       xpos = 0;
     }
   }
 }


This gives me error, I supposed I need to do some additional thing in here, any comments on that one?

Thanks in advance

Re: wrapping bult-in functions inside custom metho
Reply #1 - Sep 27th, 2005, 2:01pm
 
It looks like you're trying to declare a function from within a function.

If that's the case... that's not something to be done. Or CAN be done.
Re: wrapping bult-in functions inside custom metho
Reply #2 - Sep 27th, 2005, 4:04pm
 
right, that's just incorrect syntax. what is it you're trying to do?
Re: wrapping bult-in functions inside custom metho
Reply #3 - Sep 27th, 2005, 9:16pm
 
thanks for the replies. What I was trying to do is similar to what I did in actionscript.

something I did with AS1: - To check only with my custom function  whether the mouse is pressed or not and if it is just run the function.


custom function() {
this.onPressed = function() {
//statement
}
}

I thought there was a way to do it in processing as well. but it seems it is not the correct approach anyway.

I think I am lost a lil bit here.


Page Index Toggle Pages: 1