Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
ofirofir85
ofirofir85's Profile
1
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
handling the mousePressed and some other things...
[3 Replies]
28-Jul-2012 05:13 AM
Forum:
Programming Questions
Hi:)
this is my code:
**Edit - I tried to change to color of the block in the display function , and it stays black... I cant find the problem ..
Block[][] grid;
int cols = 16;
int rows =10;
void setup()
{
size(800,500);
grid = new Block[cols][rows];
for(int x = 0;x<cols;x++)
{
for(int y = 0;y<rows;y++)
{
grid[x][y] = new Block(x*50,y*50,50,50);
}
}
}
void draw()
{
for(int x = 0;x<cols;x++)
{
for(int y = 0 ;y<rows;y++)
{
grid[x][y].display();
}
}
}
class Block
{
int x,y,w,h,xEnd,yEnd;
boolean clicked;
Block(int xx,int yy,int ww,int hh)
{
clicked = false;
x = xx;
y = yy;
w = ww;
h =hh;
xEnd = x+50;
yEnd = y+50;
}
void display()
{
if(clicked = false)
{
fill(color(255));
rect(x,y,w,h);
}
else if(clicked = true)
{
fill(color(0));
rect(x,y,w,h);
}
}
void changeColor()
{
if(clicked = false)
{
clicked = true;
}
else if(clicked = true)
{
clicked = false;
}
}
}
void mouseClicked()
{
moveToBlock(mouseX,mouseY);
}
void moveToBlock(int mX,int mY)
{
for(int x = 0;x<cols;x++)
{
for(int y = 0 ;y<rows;y++)
{
if(mX > grid[x][y].x && mX < grid[x][y].xEnd)
{
if(mY > grid[x][y].y && mY<grid[x][y].yEnd)
{
grid[x][y].changeColor();
}
}
}
}
}
My problem is that the block is not changing the color...
please help me
(Sorry for my English ...)
«Prev
Next »
Moderate user : ofirofir85
Forum