We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey there,
Was working on my super mario game and I am quite confused how to go about collision detection between 2 classes. This is because when I enter the xpos of a class and the xpos of the other, one will be unrecognizable because it is in another class.
Any ideas?
Answers
This online example got class Bullet receiving an Asteroid object in method checkHit():
http://studio.processingtogether.com/sp/pad/export/ro.9K-kjhuONcJDZ/latest
There is no confusion, as you must prefix each field with the name of the object they belong to. Or, if you are in a class, the field without prefix belongs to the current class:
or in the Mario class:
Thankyou! :)
I wrote this in the mario class in void move() and it says cannot make a static reference to the non-static field Goomba.xpos, any ideas?
Anyone? Extremely urgent D:
You need a variable holding the reference for a Goomba object in order to access its members!
Take a look at checkHit() from my online example link above! 3:-O
Don't mix up objects (instances of classes, created with
new
), and classes (the declaration / blueprint of all objects).In Java, you can call ClassName.method() or use ClassName.field, but only for a special kind of methods and fields, called static methods / fields. And this style isn't "natural" in Processing.