Package com.sertaogames.terremoto.component

Source Code of com.sertaogames.terremoto.component.InputGravityComponent

package com.sertaogames.terremoto.component;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.sertaogames.cactus2d.Cactus2DApplication;
import com.sertaogames.cactus2d.Component;


public class InputGravityComponent extends Component{
 
  @Override
  public void init() {
    super.init();
  }
 
  Vector2 g = new Vector2();
  boolean touched = false;
 
 
  @Override
  public void update() {
    if(Gdx.input.isTouched()){
      touched = true;
      float x = (Cactus2DApplication.camera.viewportWidth/2 - Gdx.input.getX())* -0.5f;
      float y = (Cactus2DApplication.camera.viewportWidth/2 - Gdx.input.getY())*0.5f;
      g.set(x,y);
      gameObject.world.setGravity(g);
     
  //    SpriteRenderer render = gameObject.getComponent(SpriteRenderer.class);
  //    render.sprite.
  //    System.out.println("X: " + Gdx.input.getAccelerometerX());
      System.out.println("X: " + x + " Y: " + y);
  //    System.out.println("Y: " + Gdx.input.getAccelerometerY());
  //    System.out.println("Z: " + Gdx.input.getAccelerometerZ());
  //    System.out.println("R: " + Gdx.input.getRotation());
    }
    if(!touched && g.equals(new Vector2(0,0))){
      g = new Vector2();
      gameObject.world.setGravity(g);
    }
  }
 
}
TOP

Related Classes of com.sertaogames.terremoto.component.InputGravityComponent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.