정적 메서드를 호출해야하지만 정적 메서드는 인스턴스를 만들어야한다는 것을 알고 있습니다. 나는 간단한 2D 게임을 만들려고 노력하고있다. 모든 그래픽이 한 창에 나타나기를 원하는데, 각 클래스마다 몇 가지 다른 창이 나타나기를 원합니다. 그래서 graphics2D 변수 (g2d)에 이미지를 추가 할 정적 updateBackBuffer 메서드로 paintGraphics 클래스를 만들기로 결정했습니다. 이 코드를 시도했지만 내가 정적 맥락에서이를 사용할 수 없다는 오류가있어, 나는이 문제를 얻을 수있는 방법이 포함 된 개체에 액세스하기 위해'this'사용에 대한 도움이 필요합니다 - 정적 컨텍스트에서는 사용할 수 없습니다.
public static void updateBuffer(Image image, int XPos , int YPos , int Height , int Width , int Rotation, AffineTransform trans) {
trans.translate(XPos,YPos);
trans.rotate(Rotation); //More lines will probably be more lines totransform the shape more as the game gets more advanced
g2d.drawImage(image,trans,this);
}
- http://www.buggybread.com/2014/06/error-cannot-use-this- in-static-context.html –