I was looking at a tutorial for a scrolling world but when I compile I get an error saying cannot find variable - mapX
I'm getting this error on lines 65-66 where it says
thisBuildingX = building.mapX; thisBuildingY = building.mapY;
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.util.List;
import java.util.ArrayList;
/**
* Write a description of class AirWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class AirWorld extends World
{
Map map = new Map();
GreenfootImage mapImg = map.getImage();
final int MAPIMGWIDTH = mapImg.getWidth();
final int MAPIMGHEIGHT = mapImg.getHeight();
Building buildTemplate = new Building(0,0);
GreenfootImage buildImg = buildTemplate.getImage();
final int BUILDINGWIDTH = buildImg.getWidth();
final int BUILDINGHEIGHT = buildImg.getHeight();
final int MAPWIDTH = MAPIMGWIDTH * BUILDINGWIDTH;
final int MAPHEIGHT = MAPIMGHEIGHT * BUILDINGHEIGHT;
private List<Building> building = new ArrayList<Building>();
int leftBound = 0;
int bottomBound = MAPHEIGHT;
int topBound = MAPHEIGHT - getHeight();
int rightBound = getWidth();
public AirWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 600, 1);
drawMap();
update();
}
public void drawMap()
{
for(int y = 0; y < MAPIMGHEIGHT; y++)
{
for(int x = 0; x < MAPIMGWIDTH; x++)
{
int colorRGB = mapImg.getColorAt(x,y).getRGB();
if(colorRGB == Color.BLACK.getRGB())
{
int mapX = x * BUILDINGWIDTH + BUILDINGWIDTH/2;
int mapY = y * BUILDINGHEIGHT + BUILDINGHEIGHT/2;
building.add(new Building(mapX, mapY));
}
}
}
}
public void update()
{
Building thisBuilding;
int thisBuildingX;
int thisBuildingY;
int screenX;
int screenY;
for(int i=0; i < building.size(); i++)
{
thisBuilding = building.get(i);
thisBuildingX = building.mapX;
thisBuildingY = building.mapY;
if(thisBuildingX >= leftBound && thisBuildingX<=rightBound && thisBuildingY>=topBound && thisBuildingY<=bottomBound)
{
screenX = thisBuildingX - leftBound;
screenY = thisBuildingY - topBound;
if(thisBuilding.getWorld() == null)
{
addObject(thisBuilding, screenX, screenY);
}
}
}
}
}
