【发布时间】:2016-11-15 00:25:17
【问题描述】:
我正在学习游戏和应用程序开发,在第一学期,我们正在开发一个关于处理的游戏。
在我的游戏中,我在库 Game Control Plus 的帮助下使用 PS4 控制器。
如果我按下一个按钮的次数足够多,我的游戏就会崩溃并在控制台上给出这个输出(插件'Uarma'是一个在按下按钮时执行代码的函数)
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gamecontrolplus.Plug.call(Unknown Source)
at org.gamecontrolplus.ControlButton.callPlugs(Unknown Source)
at org.gamecontrolplus.ControlButton.update(Unknown Source)
at org.gamecontrolplus.ControlDevice.update(Unknown Source)
at org.gamecontrolplus.ControlIO.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.AssertionError
at org.jbox2d.dynamics.World.createBody(World.java:339)
at shiffman.box2d.Box2DProcessing.createBody(Box2DProcessing.java:203)
at Meon$Bullet.<init>(Meon.java:202)
at Meon.Uarma(Meon.java:294)
... 9 more
java.lang.RuntimeException: Error on calling plug: Uarma
at org.gamecontrolplus.Plug.call(Unknown Source)
at org.gamecontrolplus.ControlButton.callPlugs(Unknown Source)
at org.gamecontrolplus.ControlButton.update(Unknown Source)
at org.gamecontrolplus.ControlDevice.update(Unknown Source)
at org.gamecontrolplus.ControlIO.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
我对 Java 的了解并不大,因此感谢任何有关可能导致此错误的原因的帮助!
提前致谢!
这是该过程中涉及的代码:
//Variaveis
ControlIO controlo;
ControlDevice comando;
//inicia o ControlIO (vai ver que comandos estao ligados)
controlo = ControlIO.getInstance(this);
//procura comandos compativeis
comando = controlo.getMatchedDevice("playerControl");
//associa funçoes a botoes (Botão para Função)
BpFp1(); //p1 = player 1
void BpFp1() {
comando.getButton("jump").plug(this, "salto", ControlIO.ON_PRESS);
comando.getButton("punch").plug(this, "murro", ControlIO.ON_PRESS);
comando.getButton("grabWep").plug(this, "Aarma", ControlIO.ON_PRESS);
comando.getButton("useWep").plug(this, "Uarma", ControlIO.ON_PRESS);
}
void Uarma() {
println("usar armas? check");
bullets.add(new Bullet(player1.playerPos.x + 20, player1.playerPos.y, 5, 5));
}
子弹构造函数:
class Bullet {
Vec2 bulletPos;
Body bulletbody;
float dbulletLarg;
float dbulletAlt;
Bullet(float bulletX, float bulletY, float bulletLarg, float bulletAlt) {
//definir o corpo
BodyDef bulletbd = new BodyDef();
bulletbd.type = BodyType.DYNAMIC;
bulletbd.bullet = true;
bulletbd.position.set(box2d.coordPixelsToWorld(bulletX, bulletY));
//criar o corpo
bulletbody = box2d.createBody(bulletbd);
//forma
PolygonShape bulletps = new PolygonShape();
bulletps.setAsBox(box2d.scalarPixelsToWorld(bulletLarg/2), box2d.scalarPixelsToWorld(bulletAlt/2));
//o que cola a forma ao corpo
FixtureDef bulletfd = new FixtureDef();
bulletfd.shape = bulletps;
//parametros que afetam a fisica do objeto
bulletfd.density = 0;
//colar a forma ao corpo
bulletbody.createFixture(bulletfd);
dbulletLarg = bulletLarg;
dbulletAlt = bulletAlt;
bulletbody.applyLinearImpulse(new Vec2(100, 0), bulletbody.getWorldCenter(), true);
}
void display() {
bulletPos = box2d.getBodyPixelCoord(bulletbody);
pushMatrix();
translate(bulletPos.x, bulletPos.y);
rectMode(CENTER);
rect(0, 0, dbulletLarg, dbulletAlt);
popMatrix();
}
}
【问题讨论】:
-
你为什么要从葡萄牙语网站上删除这个问题?
标签: java controller crash processing jbox2d