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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:32:34+00:00 2026-05-26T18:32:34+00:00

In my app I have some draggable sprite some in the same level, other

  • 0

In my app I have some draggable sprite some in the same level, other divided in different layers, all stacked one over another.
when I drag one I need that this sprite appear always on foregorund.

If I take a sprite that was on the second layer (for example) and I need to place it over another letter that is in the first layer, I need that the one I’m touching appears over the second letter. I think I need to change the layer programmatically in the "onAreaTouched" in an if like

if(pSceneTouchEvent.isActionDown()) {

//TOCCO DELLO SPRITE

}

but how? or does exist a command to set the current touched sprite as foregorund?

EDIT
According to skyuzo I tried this way.
in my main activity I defined two different layer, one for all the sprites and another as a foreground

    Entity base = new Entity();
    Entity foreground = new Entity();

    scene.attachChild(base);
    scene.attachChild(foreground);

   spriteV = vRes.initSprite(tRegionV, scene, base, foreground); //this invoce a method that initialize a vector containing all my sprites
    
  
    
    for(int x=0;x<spriteV.size();x++){
     
        base.attachChild(spriteV.elementAt(x)); //here i attach every sprite to the scene
    
    }

in another class I’ve defined the onAreaTouched for each sprite and I’ve done this way

       @Override
            public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
                    final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
                
                if(pSceneTouchEvent.isActionDown()){
                    //TOCCO DELLO SPRITE
                                        
                    if(getY()<=261 )
                        setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY()
                                - gap);
                        
                    }
                    
                    //switch layer
                    base.detachChild(sprite);
                    fore.attachChild(sprite);
                    
                    
                }
                
                if(pSceneTouchEvent.isActionMove()){
                    //MOVIMENTO DELLO SPRITE
                    setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY()
                        - gap);
                }
                if(pSceneTouchEvent.isActionUp()){
                    //RILASCIO DELLO SPRITE
                    float x =getX();
                    float y =getY();
                    if(y<=261 ){
                        if(y>sY-20 && y<sY+20 && x>sX-20 && x<sX+20){
                            return true;
                        }
                        else {
                            val=fallInCell(x,y,this.getHeight());
                            setPosition(val[0],val[1]);
                        }
                    }
                    
                  //switch layer
                    fore.detachChild(sprite);
                    base.attachChild(sprite);
                    

                }
                return true;
            }
            
            
        };
        
        
        aux.addElement(sprite);
    }
    
    return aux;
}

but when I touch a sprite my app a force close.here the logcat error
LOGCAT ERROR

  • 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-26T18:32:34+00:00Added an answer on May 26, 2026 at 6:32 pm

    You could have two layers: One containing all of your non-foreground sprites and one containing your foreground sprite.

    Example

    void initScene() {
        scene.attachChild(spriteLayer);
        scene.attachChild(foregroundLayer);
    }
    
    void spriteTouched(Sprite sprite) {
        spriteLayer.detachChild(sprite);
        foregroundLayer.attachChild(sprite);
    }
    
    void spriteUntouched(Sprite sprite) {
        foregroundLayer.detachChild(sprite);
        spriteLayer.attachChild(sprite);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some java-app, and i want to establish a connection to some https
i have some WinForms app (Framework to develop some simple apps), written in C#.
i have some WinForms app (Framework to develop some simple apps), written in C#.
I have some settings in my app.config which I intend to be 'global' -
I have some classes in my app that don't require an ID to be
I have some things in my app that I need to store, in order
I have some code like this in a winforms app I was writing to
I have some configuration values for an asp.net web app. They will be maintained
We have some corporate intranet users using a WinForms app to work on a
I have some data that I want to store somewhere in my Rails app

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.