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

2012/6/9

Color Collision error at border

kartikitrak kartikitrak

2012/6/9

#
So I'm using colour collision detection for my game and I'm getting the follow error. java.lang.IndexOutOfBoundsException: Y is out of bounds. It was: 604 and it should have been smaller than: 600 at greenfoot.GreenfootImage.getRGBAt(GreenfootImage.java:579) at greenfoot.GreenfootImage.getColorAt(GreenfootImage.java:536) at Zorbo.onGround(Zorbo.java:50) at Platformer.checkKeys(Platformer.java:164) at Platformer.act(Platformer.java:45) at greenfoot.core.Simulation.actWorld(Simulation.java:571) at greenfoot.core.Simulation.runOneLoop(Simulation.java:506) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) I'm almost certain that it has to do with a method trying to get a colour at a border when past the border there is no colour. The border being the edge of the program screen. This is the code at line 50 in the zorbo class.
public boolean onGround()
    {
        if (getWorld().getBackground().getColorAt(getX(), getY()+18).equals(platform) || onPlatform())
        {
            return true;
        }
        return false;
    }
This is the code on line 164 in Platformer class.
if ((!zorbo.onGround() || zorbo.onPlatform()) && facingRight)
        {
            zorbo.setImage("/Sprites/jump.png");
        }
The line 45 code is just running the checkKeys method.
danpost danpost

2012/6/9

#
Line 50 of the Zorbo class has 'getY() + 18'. If the actor is below the point 'getWorld().getHeight() - 19', this check will fail.
kartikitrak kartikitrak

2012/6/9

#
How could I fix this. I've spent around 1 hour attempting to use another colourat with a yellow base at the bottom and changing the x coordinate once it reaches >=600 but none work.
danpost danpost

2012/6/9

#
Make sure the image of the actor does not cross the edge of the screen; which is why I think you put the '+ 18' in Zorbo: 50.
danpost danpost

2012/6/9

#
You may also have to put a one-pixel buffer, if you are checking the first pixel below the image.
You need to login to post a reply.