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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:13:03+00:00 2026-05-28T01:13:03+00:00

I am using this method in Andengine to scroll through a list of items,

  • 0

I am using this method in Andengine to scroll through a list of items, by setting the camera’s offset.

@Override
        public void onScroll(ScrollDetector pScollDetector, int pPointerID,
                float pDistanceX, float pDistanceY) {
            //Disable the menu arrows left and right (15px padding)
            if(mCamera.getXMin()<=15)
                menuleft.setVisible(false);
             else
                menuleft.setVisible(true);

             if(mCamera.getXMin()>mMaxX-15)
                 menuright.setVisible(false);
             else
                 menuright.setVisible(true);

            //Return if ends are reached
            if ( ((mCurrentX - pDistanceX) < mMinX)  ){                 
                return;
            }else if((mCurrentX - pDistanceX) > mMaxX){

                return;
            }

            //Center camera to the current point
            this.mCamera.offsetCenter(-pDistanceX,0 );
            mCurrentX -= pDistanceX;


            //Set the scrollbar with the camera
            float tempX =mCamera.getCenterX()-CAMERA_WIDTH/2;
            // add the % part to the position
            tempX+= (tempX/(mMaxX+CAMERA_WIDTH))*CAMERA_WIDTH;      
            //set the position
            //scrollBar.setPosition(tempX, scrollBar.getY());

            //set the arrows for left and right
            menuright.setPosition(mCamera.getCenterX()+CAMERA_WIDTH/2-menuright.getWidth(),menuright.getY());
            menuleft.setPosition(mCamera.getCenterX()-CAMERA_WIDTH/2,menuleft.getY());



            //Because Camera can have negativ X values, so set to 0
            if(this.mCamera.getXMin()<0){
                this.mCamera.offsetCenter(0,0);
                mCurrentX=0;
            }


        }

the problem is that i use this as my second scene in the Activity,
So when i navigate back to the first activity the first scene is out of position because of the camera being moved.

Is there anyway i can reset the camera when going back to the first scene?

I tried Camer.reset() to no avail.

Any suggestions?

  • 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-28T01:13:04+00:00Added an answer on May 28, 2026 at 1:13 am

    Use mCamera.setCenter(CAMERA_WIDTH / 2, CAMERA_HEIGHT / 2);. It will reset the camera position.

    By the way, I see you keep changing the menu arrows according to the camera position. You know, AndEngine has a class to handle this case 🙂 You have no reason to do it manually…
    It’s called HUD, which means Head-Up Display. You can extend the HUD class, a HUD is just a scene which is placed in a constant position on the screen. You can add as many entities to it as you want. Then, just call mCamera.setHUD(Your HUD object here); and you are done, no need to mess around with moving entities across the camera.

    Another issue I see is, you call mCamera.offsetCenter(0, 0);. offsetCenter simply adds the parameters to the current center coordinates. Adding 0 has no influence at all, so this call is useless. What are you trying to achieve? Reset the camera back to (0, 0)?

    EDIT:

    Here is a HUD example from my own game:

    public class AttackControl extends HUD {
    // ===========================================================
    // Constants          
    // ===========================================================
    
    // ===========================================================          
    // Fields         
    // =========================================================== 
    private Sprite mSprite;
    private IAttackControlClickListener mListener;
    // ===========================================================          
    // Constructors          
    // =========================================================== 
    public AttackControl(final float pX, final float pY, final Camera pCamera, final TextureRegion pTextureRegion, final IAttackControlClickListener pListener) {
        super.setCamera(pCamera);
        this.mListener = pListener;
        this.mSprite = new Sprite(pX, pY, pTextureRegion) {
            @Override
            public boolean onAreaTouched(final TouchEvent pTouchEvent, final float pX, final float pY) {
                AttackControl.this.mListener.onClick();
                return true;
            }
        };
        super.attachChild(this.mSprite);
        super.registerTouchArea(this.mSprite);
    }
    // ===========================================================          
    // Getter & Setter          
    // =========================================================== 
    
    // ===========================================================          
    // Methods for/from SuperClass/Interfaces          
    // ===========================================================  
    
    // ===========================================================          
    // Methods          
    // ===========================================================  
    
    // ===========================================================          
    // Inner and Anonymous Classes          
    // ===========================================================  
    public interface IAttackControlClickListener {
        public void onClick();
    }
    } 
    

    Then you create an instance of this class:

    final AttackControl attackControl = new AttackControl(...);
    

    and set it as the camera’s HUD:

    mCamera.setHUD(attackControl);
    

    In any case you want to use more than 1 HUD, you set 1 as a HUD then make the next one be the first one’s child scene. For example, If I have another HUD called DisplayStats and I have created it this way:

    final DisplayStats displayStats = new DisplayStats(...);
    

    Then, just set it as the attack control’s child scene. Remember – a HUD is scene! All scene operations are legal here.

    attackControl.setChildScene(displayStats);
    

    And now, the next HUD could be the child scene of displayStats… And so on.

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

Sidebar

Related Questions

when using this method public List<Field> getFieldWithoutId(List<Integer> idSections) throws Exception { try { Connection
I have a method in engine i'm using (andengine) : public final void setText(String
I am using this method - (void)keyboardWillShow:(NSNotification *)notification that is triggered when the keyboard
I am using this method in AndEngine to determine the scene being touched by
I am using this method to move a sprite side to side in AndEngine.
I have this method in my RPC service: @Override public Entrata[] getEntrate(int from, int
Should I be using this method of throwing errors: if (isset($this->dbfields[$var])) { return $this->dbfields[$var];
I'm using this method to install an application, but it doesn't put the applications
I deployed an application using this method and it worked very good. However, there
I find myself using this method a ton to perform actions based on a

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.