title: J2ME Sprite frames
body: <p>I am trying to paint only one part of Image. The image human is 159x22 length.</p>
  
  <p>In that image there is 8 human bodies (2 left, 2 right and etc.). If i try to set the Frame to <code>humanSprite.setFrame(1);</code> I will get an error since I specified in the Sprite constructor the size of an Image so there is only one frame.</p>
  
  <p>Well I have tried to divide it by 8 and I<code>ll get</code>java.lang.IllegalArgumentException`.</p>
  
  <p>Here is the class : </p>
  
  <pre><code>package org.pack.rhynn;
  
  import java.io.IOException;                     
  import javax.microedition.lcdui.game.GameCanvas;
  import javax.microedition.lcdui.game.Sprite;                
  import javax.microedition.lcdui.Graphics;
  import javax.microedition.lcdui.Image;  
  import java.util.Random;
  
  
  public class play extends GameCanvas implements Runnable{
  
  
  int sleep = 30;
  private Image map;
  private Sprite mapSprite;
  
  private Image human;
  private Sprite humanSprite;
  private int humanX = getWidth() /2;
  private int humanY = getHeight() /2;
  
  public play(){
      super(false);
  }
  
  public void start(){
  
      try {                           
          map = Image.createImage("/mapas.png");
          human = Image.createImage("/human.PNG");
      } catch (IOException ioex) {                
          System.out.println(ioex);           
      }
  
  
      mapSprite = new Sprite(map);                    
      mapSprite.defineReferencePixel(100, 150);                   
      mapSprite.setRefPixelPosition(0, 0);
  
      humanSprite = new Sprite(human,159,22);                 
      humanSprite.defineReferencePixel(1, 10);                    
      humanSprite.setRefPixelPosition(humanX, humanY);
  
  
      Thread thr = new Thread(this);
      thr.start();
  }
  
  public void run(){
      while(true){
  
          updateScreen(getGraphics());
  
      try{
          Thread.sleep(sleep);
  
      }catch(Exception e){}
  }
      }
  
  private void createBackground(Graphics g){
  
      g.setColor(0x000000);
      g.fillRect(0, 0, getWidth(), getHeight());
  
  }
  
  private void updateScreen(Graphics g){
      createBackground(g);
  
  
  
      mapSprite.setRefPixelPosition(0, 0);                
      mapSprite.paint(g);
  
      humanSprite.setRefPixelPosition(humanX, humanY);
      humanSprite.setFrame(0);
  
      humanSprite.setPosition(50,50);
      humanSprite.paint(g);
  
      flushGraphics();
  
  
  }
  
  
  
  }
  </code></pre>