Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6912321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:04:38+00:00 2026-05-27T09:04:38+00:00

I’m working on a little game/project and I decide to use AndEngine for it

  • 0

I’m working on a little game/project and I decide to use AndEngine for it because basically the Add/Remove Physics functionality in that engine was all I need. But it seems that I have a little problem with it. I have to add like 36 different pictures on a scene and be able to remove them on select. The problem is that my images are damaged and it’s not showing all the images, just the first two. Am I missing something or I’m doing it wrong? Here is what I get on my device :

Broken images

and here is my code :

public class Game extends BaseExample implements IAccelerometerListener, IOnSceneTouchListener, IOnAreaTouchListener {

// ===========================================================
// Constants
// ===========================================================
private static final int CAMERA_WIDTH = 980;
private static final int CAMERA_HEIGHT = 560;

// ===========================================================
// Fields
// ===========================================================


private BitmapTextureAtlas mBitmapTextureAtlas;

private TextureRegion firstSprite;
private TextureRegion secondSprite;
private TextureRegion thirdSprite;
private TextureRegion fourthSprite;
private TextureRegion fifthSprite;
private TextureRegion sixSprite;
private TextureRegion sevenSprite;
private TextureRegion eightSprite;
private TextureRegion nineSprite;
private TextureRegion tenSprite;

private Scene mScene;

private PhysicsWorld mPhysicsWorld;
private int mFaceCount = 0;

@Override
public Engine onLoadEngine() {
    Toast.makeText(this, "Touch the screen to add objects. Touch an object to remove it.", Toast.LENGTH_LONG).show();
    final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
    engineOptions.getTouchOptions().setRunOnUpdateThread(true);
    return new Engine(engineOptions);
}

@Override
public void onLoadResources() {
    this.mBitmapTextureAtlas = new BitmapTextureAtlas(128, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    this.firstSprite = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "1.png", 0, 0); // 64x32
    this.firstSprite.setTextureRegionBufferManaged(false);
    this.secondSprite = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "2.png", 0, 32); // 64x32
    this.secondSprite.setTextureRegionBufferManaged(false);
    this.thirdSprite = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "3.png", 0, 32); // 64x32
    this.thirdSprite.setTextureRegionBufferManaged(false);
    this.fourthSprite = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "4.png", 0, 32); // 64x32
    this.fourthSprite.setTextureRegionBufferManaged(false);
    this.fifthSprite = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "5.png", 0, 32); // 64x32
    this.fifthSprite.setTextureRegionBufferManaged(false);
    this.sixSprite = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "6.png", 0, 32); // 64x32
    this.sixSprite.setTextureRegionBufferManaged(false);
    this.sevenSprite = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "7.png", 0, 32); // 64x32
    this.sevenSprite.setTextureRegionBufferManaged(false);
    this.eightSprite = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "8.png", 0, 32); // 64x32
    this.eightSprite.setTextureRegionBufferManaged(false);
    this.nineSprite = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "9.png", 0, 32); // 64x32
    this.nineSprite.setTextureRegionBufferManaged(false);
    this.tenSprite = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "10.png", 0, 32); // 64x32
    this.tenSprite.setTextureRegionBufferManaged(false);
    this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);

}

@Override
public Scene onLoadScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

    this.mScene = new Scene();
    this.mScene.setBackground(new ColorBackground(204f, 204f, 204f));
    this.mScene.setOnSceneTouchListener(this);

    this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);

    final Shape ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2);
    final Shape roof = new Rectangle(0, 0, CAMERA_WIDTH, 2);
    final Shape left = new Rectangle(0, 0, 2, CAMERA_HEIGHT);
    final Shape right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT);

    final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef);
    PhysicsFactory.createBoxBody(this.mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef);

    this.mScene.attachChild(ground);
    this.mScene.attachChild(roof);
    this.mScene.attachChild(left);
    this.mScene.attachChild(right);

    this.mScene.registerUpdateHandler(this.mPhysicsWorld);

    this.mScene.setOnAreaTouchListener(this);

    return this.mScene;
}

@Override
public void onLoadComplete() {

}

@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
        ITouchArea pTouchArea, float pTouchAreaLocalX,
        float pTouchAreaLocalY) {

    if(pSceneTouchEvent.isActionDown()) {
        this.removeFace((Sprite)pTouchArea);
        return true;
    }

    return false;
}

@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
    if(this.mPhysicsWorld != null) {
        if(pSceneTouchEvent.isActionDown()) {
            this.addFace(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
            return true;
        }
    }
    return false;
}

@Override
public void onAccelerometerChanged(AccelerometerData pAccelerometerData) {
    final Vector2 gravity = Vector2Pool.obtain(pAccelerometerData.getX(), pAccelerometerData.getY());
    this.mPhysicsWorld.setGravity(gravity);
    Vector2Pool.recycle(gravity);
}

private void addFace(final float pX, final float pY) {
    this.mFaceCount++;

    Sprite face = null;
    Body body = null;

    final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);

    /*if(this.mFaceCount % 2 == 0) {
        face = new Sprite(pX, pY, this.firstSprite);
        body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
    } else {
        face = new Sprite(pX, pY, this.secondSprite);
        body = PhysicsFactory.createCircleBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
    }*/

    switch(this.mFaceCount){
    case 1:
            face = new Sprite(pX, pY, this.firstSprite);
            body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
        break;
    case 2:
            face = new Sprite(pX, pY, this.secondSprite);
            body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
        break;
    case 3:
            face = new Sprite(pX, pY, this.thirdSprite);
            body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
        break;
    case 4:
            face = new Sprite(pX, pY, this.fourthSprite);
            body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
        break;
    case 5:
            face = new Sprite(pX, pY, this.fifthSprite);
            body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
        break;
    case 6:
            face = new Sprite(pX, pY, this.sixSprite);
            body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
        break;
    case 7:
            face = new Sprite(pX, pY, this.sevenSprite);
            body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
        break;
    case 8:
            face = new Sprite(pX, pY, this.eightSprite);
            body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
        break;
    case 9:
            face = new Sprite(pX, pY, this.nineSprite);
            body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
        break;
    case 10:
            face = new Sprite(pX, pY, this.tenSprite);
            body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
        break;

    }

    if(this.mFaceCount<=9){
        this.mScene.registerTouchArea(face);
        this.mScene.attachChild(face);
        this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face, body, true, true));
    }
}

@Override
public void onResumeGame() {
    super.onResumeGame();

    this.enableAccelerometerSensor(this);
}


private void removeFace(final Sprite face) {
    final PhysicsConnector facePhysicsConnector = this.mPhysicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(face);

    this.mPhysicsWorld.unregisterPhysicsConnector(facePhysicsConnector);
    this.mPhysicsWorld.destroyBody(facePhysicsConnector.getBody());

    this.mScene.unregisterTouchArea(face);
    this.mScene.detachChild(face);

    System.gc();
    }

}

Any ideas where is my mistake?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:04:38+00:00Added an answer on May 27, 2026 at 9:04 am

    The main problem is with your onLoadResources method.

    A Texture (BitmapTextureAtlas in your case) is simply a large canvas containing all small images.

    Now, the method BitmapTextureAtlasTextureRegionFactory.createFromAsset(..) receives 2 numerical parameters (the 2 last parameters). These are used for the image position on the texture.

    Now, take a look at what are you doing: Loading all of the images in the same position! So some images (The last image loaded – 10.png) override the others…

    For more information, read about Textures & TextureRegions here.

    Another problem that you have in your code – In your addFace method, when you call PhysicsFactory.createBoxBody(...) the body is created and it automatically joins your physics world, even if you don’t register a physics connector between it and between the sprite, and even if you don’t attach the sprite to the scene.

    Only create a body when you are sure you’ll need it. Otherwise, make sure you destroy it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.