I'm making a game and I'm having trouble getting variables from another class. I have a Sprite class and a JPanel class. In my game, I want my score to go up once I hit a coin. My intersect coin code is in my Sprite class. How would I make it so when I hit the coin, my score goes up my 1? This code is from my JPanel class. These are variables declared all the way up top.
public static int CoinScore = 0;
private String Score = "Score :";
private String TextOnScreen="";
This is my paintcomponent method from the JPanel.
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(BackgroundImage,0,0,720,480,0,0,720,480,null);
g2d.setColor(Color.black);
g2d.fillRoundRect(25, 2, 100, 30, 10, 10);
g2d.setColor(Color.orange);
Font cp = new Font("Courier", Font.BOLD, 20);
g2d.setFont(cp);
TextOnScreen = Score + Integer.toString(CoinScore);
g2d.drawString(TextOnScreen,30,30); 30,30.
for (int i=0; i<mySprites.length; i++)
mySprites[i].drawSprite(g2d);
}
This is from my Sprite class.
if (SpriteFilename == "Resources/sprite-concepts.png" && sprites[i].SpriteFilename == "Resources/coin2.png")
{
sprites[i].SpriteVisible = false;
sprites[i].SpriteBounds.width = 0;
sprites[i].SpriteBounds.height = 0;
}
I tried putting CoinScore = CoinScore + 1 before the } in my if from the sprite class, but it says that CoinScore cannot be resolved to a variable? How would I fix it?