I'm making a game that's somewhat similar to Tetris, where a player is given blocks and must place them on a grid. Currently, when the user places a block (which is made of individual squares), individual squares of the "placedBlock" class are instantiated to re-construct the block that was placed wherever it was. For example, if the user places a 2x2 block, four squares will be made to re-construct the block.
Because each block can have one of four colours, I need the placedBlock squares to share this colour. I've tried using the setImage() method within an actor to change the image for the placedBlock class, but this does not work. All of the squares appear as they should, but they will always be the colour that the placedBlock class is initially set to. Here is the relevant code:
Essentially, I need something that will allow me to permanently change the image of the placedBlock class until it needs to be changed again.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | GreenfootImage buildBlock; buildBlock = new GreenfootImage(blockColour + "_b" + ".png" ); placedBlock placedBlock = new placedBlock(); placedBlock.setImage(buildBlock); if (blockShape.equals( "0" )){ world.addObject( new placedBlock(), getX()- 13 , getY()+ 13 ); world.addObject( new placedBlock(), getX()- 13 , getY()- 13 ); world.addObject( new placedBlock(), getX()+ 13 , getY()+ 13 ); world.addObject( new placedBlock(), getX()+ 13 , getY()- 13 ); } |