我正在學習遊戲&應用程序開發和第一學期我們正在構建一個處理遊戲。
在我的遊戲中,我在圖書館Game Control Plus的幫助下使用PS4控制器。
如果我按下一個按鈕足夠的時間,我的遊戲崩潰,並給出了控制檯上輸出(插頭「Uarma」是執行時,按下按鈕,代碼的函數)處理3.2.1 Game Control Plus庫java異常
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();
}
}
你爲什麼從葡萄牙網站刪除這個問題? –