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

2020/4/8

Cannot find symbol - method getRGB();

Ryaj987 Ryaj987

2020/4/8

#
Hi, I'm following an old tutorial for map creation and I keep getting an error in the following section of code. I have imported greenfoot.Color and java.awt.Color and it doesn't fix the issue with either. Any help would be greatly appreciated!! Here is the section of code. public void makeMap() { for(int y = 0; y < MAPIMGHEIGHT; y++) { for(int x = 0; x < MAPIMGWIDTH; x++) { int colorRGB = mapImg.getColorAt(x, y).getRGB(); if(colorRBG == Color.BLACK.getRGB()) { int mapX = x * PLATFORMWIDTH + PLATFORMWIDTH / 2; int mapY = y * PLATFORMHEIGHT + PLATFORMHEIGHT / 2; thePlatforms.add(new Platform(mapX, mapY)); } } } }
danpost danpost

2020/4/8

#
You cannot use getRGB on a greenfoot.Color object which are what all greenfoot.GreenfootImage objects consist of. Do not import java.awt.Color and do not use getRGB. Just compare the colors:
if (Color.BLACK.equals(mapImg.getColorAt(x, y)))
Ryaj987 Ryaj987

2020/4/8

#
That did it!! Thank you
You need to login to post a reply.