Android Open Source - RubeLoader Poly Spatial






From Project

Back to project page RubeLoader.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUC...

If you think the Android project RubeLoader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gushikustudios.rube;
/*ww w  .  j  a  va  2  s .  c  om*/
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.PolygonRegion;
import com.badlogic.gdx.graphics.g2d.PolygonSprite;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;

/**
 * Spatial for drawing polygon based textures.  Useful for fixture definitions.
 * 
 * @author tescott
 *
 */
public class PolySpatial {
  private PolygonSprite mSprite;
  private Body mBody;
  
  public static final float PIXELS_PER_METER = 32f;
  private static final Vector2 mTmp = new Vector2();
  
  public PolySpatial(PolygonRegion region, Color color) {
    mSprite = new PolygonSprite(region);
    mSprite.setColor(color);
    mSprite.setSize(region.getRegion().getRegionWidth()/PIXELS_PER_METER,region.getRegion().getRegionHeight()/PIXELS_PER_METER);
  }
  
  public PolySpatial(PolygonRegion region, Body body, Color color)
  {
    this(region,color);
    mBody = body;
    mTmp.set(mBody.getPosition());
    mSprite.setOrigin(0, 0);
  }

  public void render(PolygonSpriteBatch batch, float delta) {
    if (mBody != null)
    {
      mTmp.set(mBody.getPosition());
      mSprite.setRotation(mBody.getAngle()*MathUtils.radiansToDegrees);
      mSprite.setPosition(mTmp.x, mTmp.y);
      mSprite.draw(batch);
    }
    else
    {
      mSprite.draw(batch);
    }
  }

}




Java Source Code List

com.gushikustudios.rube.MainActivity.java
com.gushikustudios.rube.PolySpatial.java
com.gushikustudios.rube.PolySpatial.java
com.gushikustudios.rube.RubeDefaults.java
com.gushikustudios.rube.RubeLoaderTestDesktop.java
com.gushikustudios.rube.RubeLoaderTestDesktop.java
com.gushikustudios.rube.RubeLoaderTest.java
com.gushikustudios.rube.RubeLoaderTest.java
com.gushikustudios.rube.RubeScene.java
com.gushikustudios.rube.SimpleSpatial.java
com.gushikustudios.rube.SimpleSpatial.java
com.gushikustudios.rube.loader.RubeSceneAsyncLoader.java
com.gushikustudios.rube.loader.RubeSceneLoader.java
com.gushikustudios.rube.loader.RubeSceneSyncLoader.java
com.gushikustudios.rube.loader.serializers.BodySerializer.java
com.gushikustudios.rube.loader.serializers.FixtureSerializer.java
com.gushikustudios.rube.loader.serializers.ImageSerializer.java
com.gushikustudios.rube.loader.serializers.JointSerializer.java
com.gushikustudios.rube.loader.serializers.RubeWorldSerializer.java
com.gushikustudios.rube.loader.serializers.Vector2Serializer.java
com.gushikustudios.rube.loader.serializers.WorldSerializer.java
com.gushikustudios.rube.loader.serializers.utils.RubeImage.java
com.gushikustudios.rube.loader.serializers.utils.RubeVertexArray.java