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

  • SEARCH
  • Home
  • 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 8846751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:04:59+00:00 2026-06-14T12:04:59+00:00

I am new to Android game development and I’m using AndEngine GLES 2 Java.

  • 0

I am new to Android game development and I’m using AndEngine GLES 2 Java. In this coding I have created 2 sprite which is small_box and big_box respectively.When I drag small_box to big_box or vice versa, it repels each other.This works fine, but my problem is that 1st small_box and 1st big box repel each other, but 2nd small_box and big_box doesn’t repels.How can it be solved?. I want all small_box repels from all big_box, and when I drag small_box to another small_box it should overlap and even in big_box to another big_box also……..Plz anybody can help this by modifying this code or by using examples…….

public class SampleActivity extends SimpleBaseGameActivity {
    protected static final int CAMERA_WIDTH = 800;
    protected static final int CAMERA_HEIGHT = 480;
    private ITextureRegion Box1, Box2;;
    private Stack Stack1, Stack2;
    private Sprite small_box,big_box;
    //private final Sprite small_box = new Sprite[1];

    public EngineOptions onCreateEngineOptions() {
        final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
                new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
    }

    public void onCreateResources() {
        try {
            ITexture small_box = new BitmapTexture(this.getTextureManager(),
                    new IInputStreamOpener() {
                        public InputStream open() throws IOException {
                            return getAssets().open("gfx/small_box.png");
                        }
                    });
            ITexture big_box = new BitmapTexture(this.getTextureManager(),
                    new IInputStreamOpener() {
                        public InputStream open() throws IOException {
                            return getAssets().open("gfx/big_box.png");
                        }
                    });
            small_box.load();
            big_box.load();
            this.Box1 = TextureRegionFactory.extractFromTexture(small_box);
            this.Box2 = TextureRegionFactory.extractFromTexture(big_box);
            this.Stack1 = new Stack();
            this.Stack2 = new Stack();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public Scene onCreateScene() {
        final Scene scene = new Scene();
        scene.setBackground(new Background(1, 1, 1));
        for( int i=0;i<2;i++){
            small_box = new Sprite(i*300, 100, Box1, this.getVertexBufferObjectManager()) {
                public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,  float pTouchAreaLocalX,  float pTouchAreaLocalY) {
                    if (((Sprite) this.getmStack().peek()).getHeight() != this
                            .getHeight())
                        return false;
                    this.setPosition(pSceneTouchEvent.getX() - this.getWidth()
                            / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
                    if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP){
                        checkForCollisionsWithBoxes();
                    }
                    return true;
                  }
                private Stack getmStack() {
                    // TODO Auto-generated method stub
                    return Stack2;
                }
              };
              big_box = new Sprite(i*300, 200, Box2, this.getVertexBufferObjectManager()) {
                    public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,  float pTouchAreaLocalX,  float pTouchAreaLocalY) {
                        if (((Sprite) this.getmStack().peek()).getHeight() != this
                                .getHeight())
                            return false;
                        this.setPosition(pSceneTouchEvent.getX() - this.getWidth()
                                / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
                        if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP){
                            checkForCollisionsWithBoxes();
                        }
                        return true;
                      }
                    private Stack getmStack() {
                        // TODO Auto-generated method stub
                        return Stack1;
                    }
                  };
                  scene.attachChild(small_box);
                  scene.attachChild(big_box);
                  this.Stack1.add(big_box);
                  this.Stack2.add(small_box);
                scene.registerTouchArea(small_box);
                scene.registerTouchArea(big_box);
                scene.setTouchAreaBindingOnActionDownEnabled(true);
        }
        return scene;
    }

    private void checkForCollisionsWithBoxes() {
        if ((big_box.collidesWith(small_box) && (Stack1.size() == 0 || small_box.getHeight() < ((Sprite) Stack1.peek()).getHeight()))) {
            small_box.setPosition(100+big_box.getWidth()/2, 50+ big_box.getHeight());
            big_box.setPosition(300+small_box.getWidth()/2, 250+small_box.getHeight()/2);
    }
    }
}
  • 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-06-14T12:05:00+00:00Added an answer on June 14, 2026 at 12:05 pm

    you are only checking for the new boxes created , that’s why

    I suggest you use box2D for this, there is an example already for collisions in box2D and for filtered collisions if you need for example the small boxes to only collide with small boxes and not with big boxes

    this is the link for filtering collisions
    https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/src/org/andengine/examples/PhysicsCollisionFilteringExample.java

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

Sidebar

Related Questions

I am new to android game development and I'm using AndEngine GLES 2 Java.
I am also new to Java and Android Development, been making a simple game
hi am new in Android game development i use AndEngine i need to ploat
Hi I'm new to android development and working on a game. I currently have
I'm new to both android and game development and have been trying to create
I am new to android development, making a simple game and using onKeyDown(.....) function
I am new to android... I want to create simple android game using Andengine.
I am new at android development and java programming, but I have decided to
I'm very new on Android development. I have this: AlertDialog.Builder builder = new AlertDialog.Builder(this);
i am creating a new android application.i am using the table layout. I have

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.