我是Libgdx的新手。我有一个要求,在一场比赛中我有多个球,我想每次用户接触球时增加球的直径。我使用pixmap.drawCircle()方法创建球,每次用户触摸球时,我都会调用increaseBallDia()方法来增加球的大小。由于没有任何方法可以增加现有Pixmap的高度和宽度,因此在increaseBallDia()方法中,我创建了一个增加了宽度和高度的新Pixmap,然后绘制了一个直径增加的球。
问题是我的increaseBallDia()不能正常工作,并且没有增加像素图的高度和宽度。由于这一点,随着球直径的增加,它覆盖了整个Pixmap区域,并且看起来像矩形而不是圆形。
任何关于如何解决这个问题的建议都将不胜感激。
以下是相关的代码片段:
public class MyActor extends Actor {
int actorBallDia = 90;
Pixmap pixmap = new Pixmap(actorBallDia, actorBallDia,Pixmap.Format.RGBA8888);
float actorX, actorY;
Texture texture;
public void increaseBallDia() {
actorBallDia = actorBallDia + 5;
int radius = actorBallDia / 2 - 1;
Pixmap pixmap = new Pixmap(actorBallDia, actorBallDia,
Pixmap.Format.RGBA8888);
pixmap.drawCircle(pixmap.getWidth() / 2 , pixmap.getHeight() / 2,
radius);
pixmap.fillCircle(pixmap.getWidth() / 2 , pixmap.getHeight() / 2,
radius);
texture = new Texture(pixmap);
}
public void createYellowBall() {
pixmap.setColor(Color.YELLOW);
int radius = actorBallDia / 2 - 1;
pixmap.drawCircle(pixmap.getWidth() / 2, pixmap.getHeight() / 2,
radius);
pixmap.setColor(Color.YELLOW);
pixmap.fillCircle(pixmap.getWidth() / 2, pixmap.getHeight() / 2,
radius);
texture = new Texture(pixmap);
}
@Override
public void draw(Batch batch, float alpha) {
if (texture != null) {
batch.draw(texture, actorX, actorY);
}
}
public void addTouchListener() {
addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
MyActor touchedActor = (MyActor) event.getTarget();
touchedActor.actorTouched = true;
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y,
int pointer, int button) {
MyActor touchedActor = (MyActor) event.getTarget();
touchedActor.actorTouched = false;
}
});
}
@Override
public void act(float delta) {
if (actorTouched) {
increaseBallDia();
}
}致敬,RG
发布于 2014-11-12 15:01:41
您应该创建具有最大可能维度的像素图。当球很小的时候,只要按你的意愿缩小就行了。
https://stackoverflow.com/questions/26880366
复制相似问题