When I pass sprite in parameter and initialize that object in method but reference of Object is still null which I passed in method. Here is my Method.
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);
}
and here how I am calling it.
createAndLoadSimpleSprite(defualtCageSprite,"bg.png", this, 450, 444);
but accessing defaultCageSprite still throws a null pointer exception… I am not if sure it’s a AndEngine issue. But Can’t we pass sprites as parameters in AndEngine if no what is the work around??
You have to change your method to return the sprite object:
Now you can call:
Do not forget to attach your sprite to the
scene.