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 8213569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:09:53+00:00 2026-06-07T11:09:53+00:00

I am making a game where i require about 50 small bugs to be

  • 0

I am making a game where i require about 50 small bugs to be entering the scene from all directions. I want them to move around randomly on the screen but it doesn’t seem possible. It seems that if i use a MoveModifier, i have to provide an ending position for each sprite. Is there any way i can do this without using move modifier. I am not familiar with box 2d extension but i have seen that many people have used it for moving sprites by attaching them to a physics body. Will i be needing this extension i am not clear on that. Also i need sprites to detect collision detection between themselves and other animated sprites. How can i do this i am not so clear. Please help. Following is my code .. does it seem right

    private Runnable mStartMosq = new Runnable() {
    public void run() {
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        Log.d("Level1Activity", "width " + dm.widthPixels + " height " + dm.heightPixels);

        int i = nMosq++;

        Scene scene = Level1Activity.this.mEngine.getScene();
        float startX = gen.nextFloat() * CAMERA_WIDTH;
        float startY = gen.nextFloat() * (CAMERA_HEIGHT);   // - 50.0f);
        sprMosq[i] = new Sprite(startX, startY,
                mMosquitoTextureRegion,getVertexBufferObjectManager());
        body[i] = PhysicsFactory.createBoxBody(mPhysicsWorld, sprMosq[i], BodyType.DynamicBody, FIXTURE_DEF);

        sprMosq[i].registerEntityModifier(new SequenceEntityModifier(
                new AlphaModifier(5.0f, 0.0f, 1.0f), 
                new MoveModifier(60.0f, sprMosq[i].getX(), dm.widthPixels/2 , sprMosq[i].getY(), dm.heightPixels/2 , EaseBounceInOut.getInstance())));

        scene.getLastChild().attachChild(sprMosq[i]);
        mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(sprMosq[i], body[i], true, true));
        if (nMosq < 50) {
            mHandler.postDelayed(mStartMosq, 5000);
        }
    }
};
  • 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-07T11:09:55+00:00Added an answer on June 7, 2026 at 11:09 am

    To be honest, for this problem you don’t need box2d unless you want to do something fancy when your bugs are colliding. To do this, you need to make use of IUpdateHandler. I will give you a rough example of how I would do this for your problem:

        //Velocity modifier for the bugs. Play with this till you are happy with their speed
        private final velocity = 1.0f;
    
        sprMosq[i] = new Sprite(startX, startY,
        mMosquitoTextureRegion,getVertexBufferObjectManager());
    
        //Register update handlers
        sprMosq[i].registerUpdateHandler(new IUpdateHandler(){
    
            @Override
            public void onUpdate(float pSecondsElapsed) {
                //First check if this sprite collides with any other bug.
                //you can do this by creating a loop which checks every sprite
                //using sprite1.collidesWith(sprite2)
    
                if(collision){
                    doCollisionAction(); //Whatever way you want to do it
                } else {
                    float XVelocity;  //Velocity on the X axis
                    float YVelocity;  //Velocity on the Y axis
                    //Generate a different random number between -1 and 1
                    //for both XVelocity and YVelocity. Done using Math.random I believe
    
                    //Move the sprite
                    sprMosq[i].setPosition(XVelocity*velocity*pSecondsElapsed,
                                        YVelocity*velocity*pSecondsElapsed); 
    
                }
    
    
            }
    
            @Override
            public void reset() {
            }
    
        });
    

    This should result in random movement of each bug as every frame of the game is rendered. You can make the randomness less frequent if you want to add more bugs and eat on processing power, but you may want to check less than every frame like this algorithm is doing. To do so you might want to use a TimerHandler instead which autoresets after a certain duration.

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

Sidebar

Related Questions

I am making a game that I want compatible for all older devices to
I am making an iPhone game. I have all the required app sizes except
I am making a game in java and I want to create a simulation
I'm making some game, and I have made it pretty much all, but not
I am making an app in Android wherein I require to move an image
I'm making a tile game in c++. Right now when the game loads all
I'm going to enter a small game competition in the coming months. They require
I'm making an Android game, and I want to use a custom font for
Ok, so I'm making an html5 canvas/javascript game. I'm playing around with the idea
I am making a game in cocos2d. Game Scene has a menu button to

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.