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

随声附和 提交于 2020-01-06 07:29:48

问题


Hi how can i put a one sprite over another sprite as seen in the image below

as you can seen there is two sprite in the image (1).The sprite in the top should place over the sprite in the bottom as seen in the image (3).I tried some And engine example but did not get any solution yet .If any one know how to handle this problem please find some solution or any source.Thanks in advance

Attaching code as per the edit

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
// ===========================================================
}

回答1:


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());

Whatever your positionX is replace it by that.



来源:https://stackoverflow.com/questions/11755693/how-to-fall-a-sprite-over-another-using-and-engine-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!