I have been experimenting with using the "setColorAt" method to draw onto one of my images. Here is my code to draw onto the image:
Although When I try to move past 48 on the X or Y axis, I come up with this error:
java.lang.IndexOutOfBoundsException: Y is out of bounds. It was: 48 and it should have been smaller than: 48
at greenfoot.GreenfootImage.setRGBAt(GreenfootImage.java:601)
at greenfoot.GreenfootImage.setColorAt(GreenfootImage.java:543)
at Player1.act(Player1.java:101)
at greenfoot.core.Simulation.actActor(Simulation.java:565)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:523)
at greenfoot.core.Simulation.runContent(Simulation.java:213)
at greenfoot.core.Simulation.run(Simulation.java:203)
java.lang.IndexOutOfBoundsException: Y is out of bounds. It was: 48 and it should have been smaller than: 48
at greenfoot.GreenfootImage.setRGBAt(GreenfootImage.java:601)
at greenfoot.GreenfootImage.setColorAt(GreenfootImage.java:543)
at Player1.act(Player1.java:101)
at greenfoot.core.Simulation.actActor(Simulation.java:565)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:523)
at greenfoot.core.Simulation.runContent(Simulation.java:213)
at greenfoot.core.Simulation.run(Simulation.java:203)
java.lang.IndexOutOfBoundsException: X is out of bounds. It was: 48 and it should have been smaller than: 48
at greenfoot.GreenfootImage.setRGBAt(GreenfootImage.java:597)
at greenfoot.GreenfootImage.setColorAt(GreenfootImage.java:543)
at Player1.act(Player1.java:101)
at greenfoot.core.Simulation.actActor(Simulation.java:565)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:523)
at greenfoot.core.Simulation.runContent(Simulation.java:213)
at greenfoot.core.Simulation.run(Simulation.java:203)
java.lang.IndexOutOfBoundsException: X is out of bounds. It was: 48 and it should have been smaller than: 48
at greenfoot.GreenfootImage.setRGBAt(GreenfootImage.java:597)
at greenfoot.GreenfootImage.setColorAt(GreenfootImage.java:543)
at Player1.act(Player1.java:101)
at greenfoot.core.Simulation.actActor(Simulation.java:565)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:523)
at greenfoot.core.Simulation.runContent(Simulation.java:213)
at greenfoot.core.Simulation.run(Simulation.java:203)
Does anyone know how to fix this?
GreenfootImage image = getImage(); image.setColor(Color.BLACK); for (int currentPixel = getX() - 5; currentPixel < getX() + 5; currentPixel++) { image.setColorAt(currentPixel, getY(), Color.BLACK); }