0

こんにちは、下の画像に示すように、あるスプライトを別のスプライトの上に配置するにはどうすればよいですかここに画像の説明を入力

ご覧のとおり、画像には 2 つのスプライトがあります (1)。画像に見られるように、上部のスプライトは下部のスプライトの上に配置する必要があります (3)。And エンジンの例をいくつか試しましたが、まだ解決策が得られませんでした。 .この問題を処理する方法を知っている人がいる場合は、解決策またはソースを見つけてください。よろしくお願いします

編集に従ってコードを添付する

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

1 に答える 1

1

このコードを追加するだけです!

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

あなたのpositionXが何であれ、それに置き換えてください。

于 2012-08-01T09:07:53.267 に答える