을 사용하여 참조로 스플라이트를 전달하면 널 포인터 예외가 발생합니다. 매개 변수에 스프라이트를 전달하고 메소드에서 해당 객체를 초기화 할 때 Object의 참조가 여전히 메소드에서 전달한 null입니다. 여기 내 방법이 있습니다.andengine GLES2
public void createAndLoadSimpleSprite(Sprite sprite ,String name,
SimpleBaseGameActivity activity, int width, int height) {
BitmapTextureAtlas atlasForBGSprite = new BitmapTextureAtlas(
activity.getTextureManager(), width, height);
TextureRegion backgroundSpriteTextureRegion = BitmapTextureAtlasTextureRegionFactory
.createFromAsset(atlasForBGSprite, activity, name, 0, 0);
sprite = new Sprite(0, 0, backgroundSpriteTextureRegion,
activity.getVertexBufferObjectManager());
activity.getTextureManager().loadTexture(atlasForBGSprite);
}
여기 내가 어떻게 부르고 있는지.
createAndLoadSimpleSprite(defualtCageSprite,"bg.png", this, 450, 444);
그러나 defaultCageSprite에 액세스하면 여전히 null 포인터 예외가 발생합니다 ... AndEngine 문제인지 확실하지 않습니다. 하지만 주위에 어떤 것이 없으면 AndEngine에서 매개 변수로 스프라이트를 전달할 수 없습니까 ??
예이 메서드는 정확히 같은 방식으로 변경되었습니다. 그러나 모든 개체에 고유 한 스프라이트 참조가 있도록 클래스의 생성자에서 스프라이트를 전달해야합니다. 그래서 Sprite를 Reference로 전달하려고합니다. – Waqas
나는 무엇을 성취하려고하는지 이해하지 못한다. 그러나 이것은 자바 문제이다. 질문에'java' 태그를 추가해 보라. –
당신 말이 맞아요. 내 잘못이야 :). 다시 변수의 범위를 무시합니다 :). 감사 – Waqas