Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/** Copyright 2014 Robin Stumm ([email protected], http://dermetfan.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */
package net.dermetfan.gdx.graphics.g2d;
import java.util.Comparator;
import java.util.Iterator;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.Pools;
import net.dermetfan.utils.Function;
import static net.dermetfan.gdx.physics.box2d.Box2DUtils.height;
import static net.dermetfan.gdx.physics.box2d.Box2DUtils.minX;
import static net.dermetfan.gdx.physics.box2d.Box2DUtils.minY;
import static net.dermetfan.gdx.physics.box2d.Box2DUtils.position;
import static net.dermetfan.gdx.physics.box2d.Box2DUtils.width;
/** A {@link Box2DSprite} is a {@link Sprite} with additional drawing information and the ability to draw itself on a given {@link Body} or {@link Fixture}.
* It is supposed to be put in the user data of {@link Fixture Fixtures} or {@link Body Bodies}. Because geometrical information about bodies cannot be cached, it is faster to put Box2DSprites in the user data of Fixtures.
* @author dermetfan */
public class Box2DSprite extends Sprite {
/** the z index for sorted drawing */
private float zIndex;
/** if the width and height should be adjusted to those of the {@link Body} or {@link Fixture} this {@link Box2DSprite} is attached to (true by default) */
private boolean adjustWidth = true, adjustHeight = true;
/** if the origin of this {@link Box2DSprite} should be used when it's drawn (false by default) */
private boolean useOriginX, useOriginY;
/** for internal, temporary usage */
private static final Vector2 vec2 = new Vector2();
/** @see Sprite#Sprite() */
public Box2DSprite() {
super();
}
/** @see Sprite#Sprite(Texture, int, int) */
public Box2DSprite(Texture texture, int srcWidth, int srcHeight) {
super(texture, srcWidth, srcHeight);
}
/** @see Sprite#Sprite(Texture, int, int, int, int) */
public Box2DSprite(Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) {
super(texture, srcX, srcY, srcWidth, srcHeight);
}
/** @see Sprite#Sprite(TextureRegion, int, int, int, int) */
public Box2DSprite(TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight) {
super(region, srcX, srcY, srcWidth, srcHeight);
}
/** @see Sprite#Sprite(Texture) */
public Box2DSprite(Texture texture) {
super(texture);
}
/** @see Sprite#Sprite(TextureRegion) */
public Box2DSprite(TextureRegion region) {
super(region);
}
/** @see Sprite#Sprite(Sprite) */
public Box2DSprite(Sprite sprite) {
super(sprite);
}
/** the {@link #userDataAccessor} used by default */
public static final Function