Wieso funktioniert diese Funktion nicht?

...komplette Frage anzeigen

1 Antwort

Prüfe doch einmal, ob überhaupt ein Objekt berührt wird.

Antwort bewerten Vielen Dank für Deine Bewertung
Kommentar von einstein314
17.07.2017, 20:07
if (Main.getPlayer().touches(itemContainer)) {

Main.getInventory().addItem(itemContainer.getStoredItem());
itemContainer.setCollected(true);

}

Da habe ich eine System.out eingefügt, der text wird nie ausgegeben, wenn der Spieler die gettingRange des ItemContainers berührt und 'Q' gedrückt wird. Wieso?

0
Kommentar von einstein314
18.07.2017, 15:44

Und wieso funktioniert das nicht? Das hat bis jetzt immer funktioniert: 

public boolean isRightOf(GameObject gameObject) {

if (gameObject.getCoordinates().getxPos() + gameObject.getWidth() < getCoordinates().getxPos())
return true;
return false;

}

public boolean isLeftOf(GameObject gameObject) {

if (gameObject.getCoordinates().getxPos() > getCoordinates().getxPos() + getWidth())
return true;
return false;

}

public boolean isAbove(GameObject gameObject) {

if (getCoordinates().getyPos() + getHeight() < gameObject.getCoordinates().getyPos())
return true;
return false;

}

public boolean isBelow(GameObject gameObject) {

if (getCoordinates().getyPos() > gameObject.getCoordinates().getyPos() + gameObject.getHeight())
return true;
return false;

}

public boolean touches(GameObject gameObject) {
if (isRightOf(gameObject))
return false;
if (isLeftOf(gameObject))
return false;
if (isAbove(gameObject))
return false;
if (isBelow(gameObject))
return false;

return true;
}
0
Kommentar von einstein314
19.07.2017, 17:10

Das Problem liegt an oder in der Main Klasse:

java.lang.NoClassDefFoundError: Could not initialize class me.malte.aceAdventures1.main.Main
at me.malte.aceAdventures1.gui.AnimationPanel.paintComponent(AnimationPanel.java:26)
at javax.swing.JComponent.paint(JComponent.java:1056)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paint(JComponent.java:1065)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paint(JComponent.java:1065)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:586)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5217)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:290)
at javax.swing.RepaintManager.paint(RepaintManager.java:1272)
at javax.swing.JComponent.paint(JComponent.java:1042)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:79)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:116)
at java.awt.Container.paint(Container.java:1975)
at java.awt.Window.paint(Window.java:3904)
at javax.swing.RepaintManager$4.run(RepaintManager.java:842)
at javax.swing.RepaintManager$4.run(RepaintManager.java:814)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738)
at javax.swing.RepaintManager.access$1200(RepaintManager.java:64)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1732)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)

Was genau heisst das und wie gehe ich dagegen vor?

0

Was möchtest Du wissen?