Class SpritePlayer

java.lang.Object
uni.robot.base.SpritePlayer

public class SpritePlayer extends Object
Objeto responsable de facilitar la implementacion de animacion de Sprite.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Se crea un SpritePlayer sin ningun sprite.
    Se crea un SpritePlayer con el sprite especificado.
    SpritePlayer(Sprite sprite, double speed)
    Se crea un SpritePlayer con el sprite y velocidad especificado.
    SpritePlayer(Sprite sprite, double speed, int initialIndex)
    Se crea un SpritePlayer con el sprite, velocidad y indice incial especificado.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Si en este ciclo Update el la imagen cambio, comparando con la anterior.
    Consigue el frame acutal.
    int
    Consigue el indice del frame actual del sprite.
    double
    Consigue la velocidad de animacion.
    Consigue el sprite de este SpritePlayer.
    void
    setCurrentFrameIndex(int currentFrameIndex)
    Setea el indice actual del sprite.
    void
    setSpeed(double speed)
    Setea la velocidad actual de animacion.
    void
    setSprite(Sprite sprite)
    Setea el sprite a animar, seteando el indice frame actual a 0.
    void
    Metodo que tiene que ser llamado durante el ciclo Update, preferiblemente dentro del metodo onUpdate() de GameObject, para que la logica de animacion funcione.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpritePlayer

      public SpritePlayer(Sprite sprite, double speed, int initialIndex)
      Se crea un SpritePlayer con el sprite, velocidad y indice incial especificado.
      Parameters:
      sprite - el objeto Sprite
      speed - la velocidad de la animacion, en cuadras por ciclo Update.
      initialIndex - el indice de la imagen inicial
    • SpritePlayer

      public SpritePlayer(Sprite sprite, double speed)
      Se crea un SpritePlayer con el sprite y velocidad especificado.
      Parameters:
      sprite - el objeto Sprite
      speed - la velocidad de la animacion, en cuadras por ciclo Update.
    • SpritePlayer

      public SpritePlayer(Sprite sprite)
      Se crea un SpritePlayer con el sprite especificado.
      Parameters:
      sprite - el objeto Sprite
    • SpritePlayer

      public SpritePlayer()
      Se crea un SpritePlayer sin ningun sprite.
  • Method Details

    • getSprite

      public Sprite getSprite()
      Consigue el sprite de este SpritePlayer.
      Returns:
      el sprite de este SpritePlayer.
    • setSprite

      public void setSprite(Sprite sprite)
      Setea el sprite a animar, seteando el indice frame actual a 0.
      Parameters:
      sprite - el sprite nuevo
    • getCurrentFrameIndex

      public int getCurrentFrameIndex()
      Consigue el indice del frame actual del sprite.
      Returns:
      el frame actual.
    • setCurrentFrameIndex

      public void setCurrentFrameIndex(int currentFrameIndex)
      Setea el indice actual del sprite.
      Parameters:
      currentFrameIndex - el nuevo indice actual.
    • getSpeed

      public double getSpeed()
      Consigue la velocidad de animacion.
      Returns:
      La velocidad de animacion.
    • setSpeed

      public void setSpeed(double speed)
      Setea la velocidad actual de animacion. Una velocidad de 1, hace que la imagen cambie por cada ciclo Update. Un valor de 0 hace que la animacion pause. Un valor mayor de 1 hace que la animacion saltee algunos frames. Un valor negativo hace que se anime en reversa.
      Parameters:
      speed - La nueva velocidad de animacion.
    • getCurrentFrame

      public BufferedImage getCurrentFrame()
      Consigue el frame acutal.
      Returns:
      el BufferedImage del frame actual.
    • frameChanged

      public boolean frameChanged()
      Si en este ciclo Update el la imagen cambio, comparando con la anterior.
      Returns:
      si la imagen cambio
    • update

      public void update()
      Metodo que tiene que ser llamado durante el ciclo Update, preferiblemente dentro del metodo onUpdate() de GameObject, para que la logica de animacion funcione.