title: How to Get an Objects X position in processing
body: <p>I am trying to make Space Invaders in Processing. I am currently working on getting the enemy to move correctly. I have got them to be drawn in the right spot but I haven't gotten them to be moved correctly. Here is my code:</p>
  
  <pre><code>PImage mainPlayer;
  PImage enemyPlayer;
  
  float Xspeed = 60;
  float Yspeed = 60;
  float X;
  float Y;
  
  Enemy EnemyPlayer = new Enemy("EnemyPlayerSpaceInvaders.png", 10, 10, 6);
  
  void setup() {
   size(1400, 800);
  
   //enemyPlayer = loadImage("EnemyPlayerSpaceInvaders.png");
   mainPlayer = loadImage("MainPlayerSpaceInvaders.png");
  
  
  }
  
  void draw() {
    background(0);
  
    Enemy[] enemyPlayer = new Enemy[60];
    for (int i = 0; i &lt; 5; i += 1) {
      for (int j = 0; j &lt; 11; j += 1) {
        enemyPlayer[j *i] = new Enemy("EnemyPlayerSpaceInvaders.png", 50 + j * 100, 5 + 75 * i, 6);
      }
    }
  
    for (int i = 0; i &lt; 5; i += 1) {
      for (int j = 0; j &lt; 11; j += 1) {
        if(enemyPlayer[j * i].alive){
          enemyPlayer[j * i].Draw();
        }
        enemyPlayer[j *i].moveAndDraw(6);
      }
    }
  }
  
  
  class Enemy {
    boolean alive = true;
    float x;
    float y;
    float speed;
    String playerTexFile;
    PImage playerTex;
      Enemy(String PlayerTexFile, float X, float Y, float Speed){
       x = X;
       y = Y;
       speed = Speed;
       playerTexFile = PlayerTexFile;
      }
  
      void Draw(){
        playerTex = loadImage(playerTexFile);
       image(playerTex, x, y); 
      }
  
      void moveAndDraw(float Speed){
       playerTex = loadImage(playerTexFile);
       if(alive){
         x += Speed;
         if (x &gt;= 1300) {
            x = 100;
            y += 50;
          } 
       } 
     }
  }
  </code></pre>
  
  <p>Here is my result:
  <a href="https://i.stack.imgur.com/PbdTK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PbdTK.png" alt="enter image description here"></a></p>
  
  <p>The Draw function works but what you're seeing that is messing it up is the <code>moveAndDraw()</code> function.</p>
  
  <p>And the enemy drawings aren't moving. I have made this before with c++ SFML but in that there is a very basic getPosition function. The reason I want to get position is that right now I'm having to use inaccurate numbers as the X and Y position and for the enemy to move correctly I need to know exactly what it's position is. I have checked multiple pages on processing.org but none of them helped. I haven't found any getPosition void and all the ones I've seen other people using a void to do this I just haven't been able to get it to work. If there is some code that could get me this to work or just some function I've looked over and even a website page I could look at I'd be open to it. Please tell me anything I can do to get this working. </p>