Libgdx:动态增加Pixmap的大小

Libgdx:动态增加Pixmap的大小,libgdx,pixmap,Libgdx,Pixmap,我是Libgdx的新手。我有一个要求,在一场比赛中我有多个球,我想在每次用户触球时增加球的直径。我使用方法pixmap.drawCircle创建球,每次用户触摸球时,我调用方法increaseBallDia来增加球的大小。由于没有方法增加现有Pixmap的高度和宽度,因此在increaseBallDia方法中,我创建了一个宽度和高度增加的新Pixmap,然后绘制一个直径增加的球 问题是我的increaseBallDia工作不正常,并且没有增加Pixmap的高度和宽度。因此,随着球直径的增加,球会

我是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

您应该创建具有最大可能维度的pixmap。当球应该很小的时候,你可以随意缩小它