你怎么能把一个精灵放在另一个精灵上,如下图所示
你可以看到图像中有两个精灵(1)。顶部的精灵应该放在底部的精灵上,如图(3)所示。我尝试了一些和引擎的例子,但没有得到任何解决方案。如果有人知道如何处理这个问题,请找到一些解决方案或任何来源。谢谢提前
根据编辑附加代码
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 :(得分: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());
无论你的位置是什么,取而代之的都是。