This site requires JavaScript, please enable it in your browser!
Greenfoot back
cxcpio
cxcpio wrote ...

2020/11/18

Changing color of an object

cxcpio cxcpio

2020/11/18

#
I would like to change the color of a gird of squares that I made. Firstly, I have no clue how to change the color of an object. Secondly, I create the grid late in my code (overlapping the first grid) and I don't want that grid to change color. Thanks in advance
danpost danpost

2020/11/18

#
cxcpio wrote...
I would like to change the color of a gird of squares that I made. Firstly, I have no clue how to change the color of an object. Secondly, I create the grid late in my code (overlapping the first grid) and I don't want that grid to change color. Thanks in advance
Show code of grid you made.
danpost danpost

2020/11/19

#
At least realize that there is a GreenfootImage background field in the World class and a GreenfootImage image field in the Actor class. Any method found in the GreenfootImage API documentation can be applied to the objects assigned to these fields.
cxcpio cxcpio

2020/11/19

#
public void grid(int size, int[][] Xcoordinates, int[][] Ycoordinates)
    {
        int offsetX=17;
        int offsetY=17;
        int square=0;
        for (int x=0;x<size;x++)
        {
            offsetY=17;
            for (int y=0;y<size;y++)
            {
                addObject(new squares(),offsetX,offsetY);               
                Xcoordinates[x][y]=offsetX;
                Ycoordinates[x][y]=offsetY;
                empty[square]=true;
                square=square+1;
                offsetY=offsetY+35;               
            }
            offsetX=offsetX+35;
        }
    }
Here is the code for the grid
danpost danpost

2020/11/19

#
cxcpio wrote...
<< Code Omitted >> Here is the code for the grid
So, your grid is made up of squares actors. Show code of squares class. Also, are you wanting to change the color of the entire grid (all squares) at once or have the squares change colors individually?
cxcpio cxcpio

2020/11/22

#
For now I have nothing in my squares class. I would like to change the color of all squares at once but only for the bottom grid. Not the overlapping grid.
danpost danpost

2020/11/22

#
cxcpio wrote...
For now I have nothing in my squares class. I would like to change the color of all squares at once but only for the bottom grid. Not the overlapping grid.
Both grids are comprised of squares actors?
cxcpio cxcpio

2020/11/23

#
They used to be made from the same squares actors but I have changed that now so it might be easier?
cxcpio cxcpio

2020/11/23

#
I found out how! Thank you for your help anyways!
You need to login to post a reply.