Render.java :  » Game » ulooked-games » com » ulooked » engine » components » Android Open Source

Android Open Source » Game » ulooked games 
ulooked games » com » ulooked » engine » components » Render.java
package com.ulooked.engine.components;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ulooked.engine.Entity;
import com.ulooked.engine.GameEngine;
import com.ulooked.engine.SpriteAnimationParams;
import com.ulooked.engine.commands.AddTextureCommand;
import com.stickycoding.rokon.*;

public class Render extends Component {
  private Sprite _sprite;
  private SpriteAnimationParams _animParams;
  private int _zIndex;

  public Render() {
    super(ComponentType.Render);
  }
  
  public Render(Render other) {
    super(other);
    _sprite = new Sprite(other._sprite.x,other._sprite.y,
        other._sprite.getWidth(),other._sprite.getHeight());
    _sprite.setTexture(other._sprite.getTexture());
    _animParams = other._animParams;
    _zIndex = other._zIndex;
  }

  public void setSprite(Sprite sprite) {
    this._sprite = sprite;
  }

  public Sprite getSprite() {
    return _sprite;
  }

  public void setZIndex(Integer zIndex) {
    this._zIndex = zIndex;
  }

  public int getZIndex() {
    return _zIndex;
  }

  public boolean initFromJson(JsonObject object) {
    JsonObject tex = object.get("texture").getAsJsonObject();
    String texName = tex.get("src").getAsString();
    Texture texture = new Texture(getAssetsPath()+"/"+texName);
    GameEngine.self.process(new AddTextureCommand(texture));
    
//    Integer tileRows = 1, tileCols = 1;
//    JsonElement currElem = tex.get("tileRows");
//    
//    if (currElem != null) {
//      tileRows = currElem.getAsInt();
//      
//      currElem = tex.get("tileCols");
//      
//      if (currElem != null) {
//        tileCols = currElem.getAsInt();
//      }
//    }
//        
//    if (tileCols > 1 || tileRows > 1) {
//      //texture.setTileCount(tileCols, tileRows);
//    }        
    _sprite = new Sprite(0,0,32,32);
    _sprite.setTexture(texture);
    //TODO: animation params
    return true;
  }

  @Override
  public void release() {
    _sprite.remove();
  }

  @Override
  public Component clone() {
    return new Render(this);
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.