【问题标题】:How Can I Create Bullet In 2D Libgdx Game如何在 2D Libgdx 游戏中创建子弹
【发布时间】:2018-12-04 13:39:41
【问题描述】:
我创建了一个 2D Libgdx 游戏。游戏看起来像 Flappy Bird 但我想添加子弹我搜索了大约 1 周但我没有找到任何东西。
实际上我发现了,但我认为它们很复杂。我不想自动射击。用户只有 3 颗子弹并发射它们。
如何在我的游戏类中创建子弹。如果有简单的方法可以创建它们,谁能告诉我。enter image description here
【问题讨论】:
标签:
android-studio
libgdx
2d
【解决方案1】:
您的问题比较抽象,没有任何代码 sn-ps,但我的建议是面向对象的方法。
创建一个 Bullet 类来存储子弹的属性。 (例如速度、位置)
在您的播放器类中,创建一个 Bullet 对象数组。
设置用户点击“拍摄”按钮时的事件监听器。当他们确实向您的阵列添加项目符号时。起始位置将在您玩家的旁边。
当子弹接触或离开屏幕时,将其从阵列中移除。 (这部分要小心;))。
对不起,我的回答不是很详细,但没有代码,我只能提供。编码愉快!
【解决方案2】:
感谢您的帮助。我想添加一些关于子弹的内容。我想触摸我在游戏中创建的按钮,当我触摸按钮子弹应该触发时,我怎么能做到这一点,但它没有绘制我的子弹是我的代码
Table table = new Table();
table.setFillParent(true);
table.setDebug(true);
stage.addActor(table);
Skin skin = new Skin(Gdx.files.internal("skin/glassy-ui.json"));
final TextButton atis = new TextButton("", skin);
table.row().pad(10, 0, 10, 0);//UÇAK1 BOTUNUN YERİ
table.add(atis).uniformX();
atis.addListener( new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
stage= new Stage();
Gdx.input.setInputProcessor(stage);
batch.begin();
batch.draw( bulletTexture, birdX+testBullet.bulletLocation.x, birdY );
batch.end();
};
});