- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在我的游戏中有一辆坦克。我有一个扩展 Sprite
的 Barrel 类,这个类负责处理与桶相关的东西,其中之一就是射击时的爆炸动画。这就是我尝试这样做的方式:
batch.draw(currShotAnimation,
b2body.getPosition().x - currShotAnimation.getRegionWidth() / 2,
b2body.getPosition().y + 10,
0,
0,
currShotAnimation.getRegionWidth(),
currShotAnimation.getRegionHeight(),
1,
1,
getRotation());
当坦克向前看时它正在工作:
但是当他看向不同的地方时,它看起来很奇怪:
编辑:
在尝试了 Abhishek Aryan
的建议后(我的米像素是一个):
batch.draw(currShotAnimation,
b2body.getPosition().x + offset * MathUtils.cosDeg(getRotation()),
b2body.getPosition().y + offset * MathUtils.sinDeg(getRotation()),
currShotAnimation.getRegionWidth()/2f,
currShotAnimation.getRegionHeight()/2f,
currShotAnimation.getRegionWidth(),
currShotAnimation.getRegionHeight(),
1,
1,
getRotation());
最佳答案
b2body
是你的 box2d body 吗?如果是,则将米转换为像素以在屏幕上绘制。
private float offset=10;
private float METER_PIXEL=32;
batch.draw(textureRegion,b2body.getPosition().x*METER_PIXEL+ offset *MathUtils.cosDeg(getRotation()),b2body.getPosition().y*METER_PIXEL+ offset*MathUtils.sinDeg(getRotation()),currShotAnimation.getRegionWidth()/2f,currShotAnimation.getRegionHeight()/2f,currShotAnimation.getRegionWidth(),currShotAnimation.getRegionHeight(),1,1,getRotation());
在这里,您使用 sprite Rotation 来旋转火焰动画。所以你需要根据 b2dbody 旋转来旋转你的 Sprite,这样你就可以在这里使用否则你需要以弧度获取 b2body 旋转并转换成度数并在这里使用。
我在这里测试了 TextureRegion 的偏移量
public class TestGame extends Game implements InputProcessor{
private SpriteBatch spriteBatch;
private Sprite sprite;
private TextureRegion textureRegion;
private float offset = 20;
private firstTex,secondTex;
@Override
public void create() {
spriteBatch=new SpriteBatch();
textureRegion=new TextureRegion(firstTex=new Texture("im.png"));
sprite=new Sprite(secondTex=new Texture("xyz.png"));
sprite.setPosition(100,100);
Gdx.input.setInputProcessor(this);
}
@Override
public void render() {
Gdx.gl.glClearColor(1,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
spriteBatch.begin();
sprite.draw(spriteBatch);
spriteBatch.draw(textureRegion,sprite.getX()+ offset *MathUtils.cosDeg(sprite.getRotation()),sprite.getY()+(offset)*MathUtils.sinDeg(sprite.getRotation()),sprite.getWidth()/2f,sprite.getHeight()/2f,sprite.getWidth(),sprite.getHeight(),1,1,sprite.getRotation());
spriteBatch.end();
if(Gdx.input.isTouched()){
float rotation=sprite.getRotation();
rotation++;
sprite.setRotation(rotation);
}
}
@Override
public boolean keyDown(int keycode) {
return false;
}
@Override
public boolean keyUp(int keycode) {
return false;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
float rotation=sprite.getRotation();
rotation++;
sprite.setRotation(rotation);
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
@Override
public void dispose(){
firstTex.dispose();
secondTex.dispose();
spriteBatch.dispose();
}
}
关于java - 来自枪的 Libgdx 爆炸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42453665/
我正在尝试在 Pyspark 中实现自定义爆炸。我有 4 列,它们是具有几乎相同架构的结构数组(一列结构包含的字段比其他三列少一个)。 对于我的 DataFrame 中的每一行,我有 4 列是结构数组
我如何分解 [group_concat(DISTINCT LineItem.ItemID)] => 600278,WH1502。 我试过了,但什么也没显示 $result = mysqli_query
假设我有一个数据框 df : C1 C2 C3 C4 C5 0 [A] [1] s1 [123]
我的数据在其中一个字段中具有嵌套映射。例如,数据位于名为“customers”的表中,如下所示: 姓名:比尔·琼斯 地址:{"billing":{"street":"123 Main", "city"
我有两个独立的项目(ejb,web),完全独立。问题是我想通过maven将ejb项目添加到web依赖项,但我正在寻找一个爆炸依赖项而不是jar,所以当我编译ejb项目时,更改会立即在web项目中生效。
我正在将我的 ROOT.war 文件复制到 Tomcat 6.0 的 webapps 中。有没有一种方法可以在复制时分解文件。即当我的脚本在 webapps 中复制它时..它应该爆炸并创建 ROOT
我有一个体素世界,类似于 Minecraft。每个体素( block )的大小为 1x1x1。 我想计算具有给定爆炸半径的特定位置的爆炸破坏,这意味着游戏将在该位置周围破坏体素(给定所需的半径)。 意
在我的游戏中有一辆坦克。我有一个扩展 Sprite 的 Barrel 类,这个类负责处理与桶相关的东西,其中之一就是射击时的爆炸动画。这就是我尝试这样做的方式: batch.draw(currShot
我一直在严重依赖 CSS 来创建我正在开发的网站。现在,所有 CSS 样式都在每个标签的基础上应用,所以现在我试图将其移动到更多的外部样式以帮助将来进行任何更改。 但现在的问题是我注意到我收到了“CS
我有一个 NSString:@"1a,1b,1c,1d,5c"。我想把这个 NSString 分成一个 NSMutableArray,但我不知道如何。我认为它相当简单,但我找不到它(也许是因为我的英语
我正在尝试使用 QML Canvas.requestAnimationFrame 来绘制一些自定义动画。我预计所提供的回调每帧调用一次,大约每秒 60 次。我的代码是: Canvas { id
我有: df = pd.DataFrame({'col1': ['asdf', 'xy', 'q'], 'col2': [1, 2, 3]}) col1 col2 0 asdf 1
在对 this question 的回答中MathWorks 支持团队声明: It is also possible to overload the ! (bang) operator by crea
好吧——穿上你 70 年代的喇叭裤,然后走进 WayBack 机器……迪斯科又活了,伙计们……(我怀疑这有标签……) 我需要 UUCP 的继任者。对你们这些 child 来说,在互联网出现之前和拜赛因
我今天阅读的一个问题的答案建议将应用程序部署为展开(解压缩)WAR .这让我开始思考。 我对 JBoss/Tomcat 所做的每一次部署都使用了 WAR/EAR文件。至少在我的内存中。 这些年来我一直
我有一个包含以下内容的 Spark Dataframe: 姓名E1E2E3abc456 我需要各种 E列成为新列中的行,如下所示: 姓名值E类型abc4E1abc5E2abc6E3 This answ
$user = $this->user; $user->name = $request['name']; $user->email = $request
我正在使用 Java 1.6、JBoss 5.1、EJB 3 和 Hibernate 2。每次部署 ear 时,如果 jar 是紧凑型(未展开),应用程序将无法运行。但是,当我炸开 jar 然后将其放
我是 dask 的新手,请多多包涵。 我有一个 JSON 文件,其中每一行都有以下架构: { 'id': 2, 'version': 7.3, 'participants': range(10)
我尝试使用 Chai Should 风格的断言,但是下面的语句让 Mocha 爆炸了。这是我完整的 Require block : /**
我是一名优秀的程序员,十分优秀!