Search code examples
javaimagebufferedimageslick2d

Can't draw a Buffered Image


I'm using this code to try and draw an image :

g.drawImage(Tile.background, (int)spritePositionX, (int)spritePositionY, null);

Here is the my tile class for Tile.background :

public class Tile {
public static int size = 40;
public static BufferedImage terrain, background, items, characters;
public Tile(){
    try{
        Tile.background = ImageIO.read(new File("res/bg.png"));
        Tile.terrain = ImageIO.read(new File("res/terrain.png"));
        Tile.items = ImageIO.read(new File("res/items.png"));
        Tile.characters = ImageIO.read(new File("characters/bg.png"));
    }catch(Exception e){
        System.out.println("Error loading images.");
    }
}

}

It gives me this error : The method drawImage(Image, float, float, Color) in the type Graphics is not applicable for the arguments (BufferedImage, int, int, null) Thanks in advance

These are my imports in the class that the g.drawImage is in :

import javax.swing.ImageIcon;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
import java.awt.Rectangle;

Solution

  • You're trying to use Slicks implementation of the Graphics object which doesn't have a method with the arguments you're providing. Slick is dead anyway. Either switch to LIBGDX or just use Java's 2d API.