How to drop a sprite over another using And engine in android?

Hi, how can I put one sprite over another sprite as shown in the image below enter image description here

as you can see, there are two sprites in the image (1). The sprite above should be located above the sprite below, as seen in the image (3). I tried an example and an example engine, but did not get any solution. If anyone knows how to handle this problem, find some solution or any source. thanks in advance

Attachment of code according to editing

public class MainActivity extends SimpleBaseGameActivity {
// ===========================================================
// Constants
// ===========================================================

private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
private static final int LAYER_COUNT = 4;
 Scene scene;
// ===========================================================
// Fields
// ===========================================================

private Camera mCamera;

private Font mFont;

private BitmapTextureAtlas mBitmapTextureAtlas;
private ITextureRegion mBadgeTextureRegion;
private ITextureRegion mNextTextureRegion;

private static final IEaseFunction[][] EASEFUNCTIONS = new IEaseFunction[][]{
    new IEaseFunction[] {
            EaseLinear.getInstance(),
            EaseLinear.getInstance(),
            EaseLinear.getInstance()
    },

};

private int mCurrentEaseFunctionSet = 0;

private final Sprite[] mBadges = new Sprite[1];
//private final Text[] mEaseFunctionNameTexts = new Text[3];

// ===========================================================
// Constructors
// ===========================================================

// ===========================================================
// Getter & Setter
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================


public EngineOptions onCreateEngineOptions() {
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera);
}


public void onCreateResources() {
    /* The font. */
    final ITexture fontTexture = new BitmapTextureAtlas(this.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
    this.mFont = new Font(this.getFontManager(), fontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32, true, Color.WHITE);
    this.mFont.load();

    /* The textures. */
    this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 256, 128, TextureOptions.BILINEAR);
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    this.mNextTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "next.png", 0, 0);
    this.mBadgeTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "badge.png", 97, 0);

    this.mBitmapTextureAtlas.load();
}


public Scene onCreateScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

scene = new Scene();



    /* Create the sprites that will be moving. */

    this.mBadges[0] = new Sprite(0, CAMERA_HEIGHT - 300, this.mBadgeTextureRegion, this.getVertexBufferObjectManager());


    scene.attachChild(this.mBadges[0]);

    return scene;
}


public void onGameCreated() {

    this.reanimate();
    }








// ===========================================================
// Methods
// ===========================================================


private void reanimate() {
    this.runOnUpdateThread(new Runnable() {

        public void run() {
            final IEaseFunction[] currentEaseFunctionsSet = EASEFUNCTIONS[MainActivity.this.mCurrentEaseFunctionSet];
        //  final Text[] easeFunctionNameTexts = MainActivity.this.mEaseFunctionNameTexts;
            final Sprite[] faces = MainActivity.this.mBadges;


            //  easeFunctionNameTexts[i].setText(currentEaseFunctionsSet[i].getClass().getSimpleName());
                final Sprite face = faces[0];

                face.clearEntityModifiers();

                final float y = face.getY();
                face.setPosition(0, y);
                face.registerEntityModifier(new MoveModifier(3, 0, CAMERA_WIDTH - face.getWidth(), y, y, currentEaseFunctionsSet[0]));

        }
    });
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
0
source share
1 answer

Just add this code!

this.mBadges[1] = new Sprite(0, CAMERA_HEIGHT - 300, this.mBadgeTextureRegion, this.getVertexBufferObjectManager());


scene.attachChild(this.mBadges[1]);
this.mBadges[1].setPosition(positionX, mBadges[0].getY()-mBadges[1].getHeight());

No matter what your position, X will replace it with.

+1
source

All Articles