0
\$\begingroup\$

This question might be naive, I'm just making sure I grasp the API. Suppose you have an array of 3 objects

  • Is array.get(o) the same as array.first(); and array.get(2) the same as array.peek()?

Suppose you have an object moving on screen

  • Is array.get(o).x the same as array.get(o).getX()

By reading the API it seems to me that x returns position of the object while getX() returns the position of the mouse, or the user's finger whenever he touched the screen. But if that's true then I shouldn't be allowed to use getX() on an object like I did above

\$\endgroup\$
  • \$\begingroup\$ getX is a getter for x \$\endgroup\$ – Bálint Jan 26 '17 at 9:19
3
\$\begingroup\$

Yes and probably.

Array#first() returns the first element in the array, I.e. element 0. So it's the same as Array#get(0).

Array#peek (or Array#pop()) returns the last element in the array, I.e. element array.size - 1 (which in your case is 3 - 1 = 2).

As for the question that object.x is the same as object.getX() depends on the definition of the getX() method in the object's class. Most likely they are equal since getX() is the typical syntax of a getter which gets the variable x. There's no reason to think that it returns the mouse position unless the object is Gdx.input since getX() in the Input class gets the mouse position.

\$\endgroup\$
  • \$\begingroup\$ I'll take your word and balint and use getX \$\endgroup\$ – Lynob Jan 26 '17 at 10:44
  • \$\begingroup\$ @Lynob basically a getter method is a public method to access a private variable from outside it's class. A pretty fundamental thing in java. I recomens reading up on it. \$\endgroup\$ – sistergodiva Jan 27 '17 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.