首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Libgdx:动态增加Pixmap的大小

Libgdx:动态增加Pixmap的大小
EN

Stack Overflow用户
提问于 2014-11-12 14:07:02
回答 1查看 501关注 0票数 0

我是Libgdx的新手。我有一个要求,在一场比赛中我有多个球,我想每次用户接触球时增加球的直径。我使用pixmap.drawCircle()方法创建球,每次用户触摸球时,我都会调用increaseBallDia()方法来增加球的大小。由于没有任何方法可以增加现有Pixmap的高度和宽度,因此在increaseBallDia()方法中,我创建了一个增加了宽度和高度的新Pixmap,然后绘制了一个直径增加的球。

问题是我的increaseBallDia()不能正常工作,并且没有增加像素图的高度和宽度。由于这一点,随着球直径的增加,它覆盖了整个Pixmap区域,并且看起来像矩形而不是圆形。

任何关于如何解决这个问题的建议都将不胜感激。

以下是相关的代码片段:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2014-11-12 15:01:41

您应该创建具有最大可能维度的像素图。当球很小的时候,只要按你的意愿缩小就行了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26880366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档