Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualKhatharr

Posted 18 May 2013 - 05:57 PM

I still don't know about slowdown because I don't know what determines how often your draw code is called. I do know now that you have simulation logic in your draw code, which is a no-no. Also, that function is a significant violation of DRY.

 

//put the position limits in an array

public void draw(Graphics g) {
  int xpos = position.getX();
  for(int i = 0; i < 5; ++i) {
    if(xpos < positionLimits[i]) {
      g.drawImage(alienMovementAnimation.get(i), xpos, (int)position.getY(), null);
      break;
    }
  }

  //Game.setGameWon(true); //do this in the logic, not in the drawing!

}

#3Khatharr

Posted 18 May 2013 - 05:51 PM

I still don't know about slowdown because I don't know what determines how often your draw code is called. I do know now that you have simulation logic in your draw code, which is a no-no. Also, that function is a significant violation of DRY.

 

//put the position limits in an array

public void draw(Graphics g) {
  int xpos = position.getX();
  int anim = 0;
  for(int i = 0; i < 5; ++i) {
    if(positionLimits[i] > xpos) {continue;}
    anim = i + 1;
  }
  if(anim <= 4) {
    g.drawImage(alienMovementAnimation.get(anim), xpos, (int)position.getY(), null);
  }
  //Game.setGameWon(true); //do this in the logic, not in the drawing!
}

#2Khatharr

Posted 18 May 2013 - 05:50 PM

I still don't know about slowdown because I don't know what determines how often your draw code is called. I do know now that you have simulation logic in your draw code, which is a no-no. Also, that function is a significant violation of DRY.

 

//put the position limits in an array

public void draw(Graphics g) {
  int xpos = position.getX();
  int anim = 0;
  for(int i = 0; i < 5; ++i) {
    if(xpos >= positionLimits[i]) {break;}
    anim = i + 1;
  }
  if(anim <= 4) {
    g.drawImage(alienMovementAnimation.get(anim), xpos, (int)position.getY(), null);
  }
  //Game.setGameWon(true); //do this in the logic, not in the drawing!
}

#1Khatharr

Posted 18 May 2013 - 05:35 PM

I still don't know about slowdown because I don't know what determines how often your draw code is called. I do know now that you have simulation logic in your draw code, which is a no-no. Also, that function is a significant violation of DRY.


PARTNERS