我无法让我的卡片演员执行动作(我在图像和纹理上添加和执行动作没有问题)。这是我的Card.class代码:
public class Card extends Actor {
final float CARD_WIDTH = 500 * cardScale;
final float CARD_HEIGHT = 726 * cardScale;
String face, suit;
public Texture cardFace = new Texture("CardTextures/" + face + suit + ".png");
Vector2 position = new Vector2(0, 0);
public Card(String face, String suit, Vector2 position) {
this.face = face;
this.suit = suit;
this.position = position;
setBounds(position.x, position.y, CARD_WIDTH, CARD_HEIGHT);
}
public Card(String face, String suit) {
this.face = face;
this.suit = suit;
this.position = position;
setBounds(position.x, position.y, CARD_WIDTH, CARD_HEIGHT);
}
@Override
public void act(float delta) {
super.act(delta);
}
@Override
public void draw(Batch batch, float alpha) {
batch.draw(cardFace, position.x, position.y, cardFace.getWidth() * cardScale, cardFace.getHeight() * cardScale);
}
public String getFace() {
return face;
}
public String getSuit() {
return suit;
}
public void setCardPosition(Vector2 position) {
this.position = position;
}
public void setCardFaceTexture() {
cardFace = new Texture(("CardTextures/" + this.getFace() + this.getSuit() + ".png"));
}
}
每当我尝试使用卡片演员执行某项操作时,它都无法正常工作。即使我将动作放在Create()方法中,它也不起作用。我试过这个:
moveAction = new MoveToAction();
moveAction.setPosition(300f, 0f);
moveAction.setDuration(10f);
Card card = new Card("two", "spades");
card.addAction(moveAction);
这是我的渲染方法:
@Override
public void render() {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
updateActorBounds();
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
font.draw(batch, "FPS:" + Gdx.graphics.getFramesPerSecond(), TABLE_WIDTH / 2 - 65, TABLE_HEIGHT / 2 - 10);
batch.end();
}
答案 0 :(得分:0)
您的Card
使用自己的位置Vector2 position
。当您向MoveAction
添加Card
时,该操作会访问并更改x
类中的y
和Actor
变量 - 而非您的变量。这意味着,如果您希望Card
显示操作应该显示的位置,而不是在position.x, position.y
绘图,则需要在getX(), getY()
绘制。
您的构造函数将如下所示:
public Card(String face, String suit, Vector2 position) {
this.face = face;
this.suit = suit;
setBounds(position.x, position.y, CARD_WIDTH, CARD_HEIGHT);
}
您的绘制方法如下:
@Override
public void draw(Batch batch, float alpha) {
batch.draw(cardFace, getX(), getY(), cardFace.getWidth() * cardScale, cardFace.getHeight() * cardScale);
}