本文整理汇总了Java中com.badlogic.gdx.math.Polygon.setOrigin方法的典型用法代码示例。如果您正苦于以下问题:Java Polygon.setOrigin方法的具体用法?Java Polygon.setOrigin怎么用?Java Polygon.setOrigin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.math.Polygon
的用法示例。
在下文中一共展示了Polygon.setOrigin方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPolygon
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* Retrieves a polygon from the polygon cache, with a specified width and height
*
* @param name the polygon to retrieve
* @param width the width of the polygon
* @param height the height of the polygon
*
* @return the loaded polygon
*/
public static Polygon getPolygon(String name, float width, float height) {
if(! polygons.containsKey(name))
loadPolygon(name);
Polygon temp = polygons.get(name);
float[] tempVertices = temp.getVertices();
float[] returnVertices = new float[tempVertices.length];
for(int i = 0; i < tempVertices.length; i++)
{
if(i % 2 == 0)
returnVertices[i] = tempVertices[i] * width;
else returnVertices[i] = tempVertices[i] * height;
}
Polygon ret = new Polygon(returnVertices);
ret.setOrigin(width/2, height/2);
return ret;
//NOTE: Origin might need to be revisited
}
示例2: Bullet
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public Bullet(Sprite sprite)
{
this.sprite = sprite;
weapon = new Weapon(START_DAMAGE, START_ROF, START_MAGSIZE, START_RECOIL, START_KNOCKBACKPOWER);
velocity = new Vector2();
vertices = new float[]{
0, 0,
0, sprite.getHeight(),
sprite.getWidth(), sprite.getHeight(),
sprite.getWidth(), 0 };
bounds = new Polygon(vertices);
bounds.setOrigin(this.sprite.getWidth() / 2, this.sprite.getHeight() / 2);
isOutOfScreen = false;
isUsed = false;
}
示例3: CastleFirebar
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public CastleFirebar(MapObject mapObject) {
super(mapObject, new Vector2());
setRenderingSize(3, 0.5f);
setOrigin(0, 0.25f);
bounds=new Rectangle(getX() + offset.x, getY(), getWidth(), getHeight());
polygon = new Polygon(new float[]{getX() + offset.x,getY(),
getX() + offset.x, getY()+getHeight()-offset.y,
getX() + offset.x + getWidth(), getY()+getHeight()-offset.y,
getX() + offset.x + getWidth(), getY()
});
polygon.setOrigin(getX() + offset.x, getY() + 0.25f);
moveable = false;
collidableWithTilemap = false;
gravitating = false;
killableByPlayer = false;
killableByFireball = false;
explodeFireball = false;
float rotation = Float.parseFloat((String)mapObject.getProperties().get("angle"));
rotateBy(rotation);
polygon.setRotation(getRotation());
}
示例4: addPlayer
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public Entity addPlayer(Position pos, Velocity vel, Health health, Invincibility invisible)
{
Entity player = new Entity();
player.add(pos);
player.add(vel);
player.add(health);
player.add(invisible);
float[] playerCoords = {
25.0f, 0.0f,
50.0f, 25.0f,
25.0f, 50.0f,
0.0f, 25.0f
};
Polygon poly = new Polygon(playerCoords);
poly.setOrigin(25.0f, 25.0f);
CollisionBox box = new CollisionBox(poly);
player.add(box);
player.add(new Graphics(playerSprite));
return player;
}
示例5: rotate2
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* @param originX , originY, rotation point relative to self
*/
private void rotate2(Rectangle sourceRect, Rectangle destRect, float originX, float originY, float rotate)
{
float x = sourceRect.x;
float y = sourceRect.y;
float centerX = sourceRect.x + originX;
float centerY = sourceRect.y + originY;
float w = sourceRect.width;
float h = sourceRect.height;
Polygon polygon = new Polygon(new float[]{
x, y,
x, y + h,
x + w, y + h,
x + w, y
});
polygon.setOrigin(centerX, centerY);
polygon.setRotation(rotate);
destRect.set(polygon.getBoundingRectangle());
}
示例6: read
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
@Override
public Polygon read (Kryo kryo, Input input, Class<Polygon> type) {
int length = input.readInt();
float[] vertices = input.readFloats(length);
Polygon polygon = new Polygon(vertices);
polygon.setPosition(input.readFloat(), input.readFloat());
polygon.setOrigin(input.readFloat(), input.readFloat());
polygon.setRotation(input.readFloat());
polygon.setScale(input.readFloat(), input.readFloat());
return polygon;
}
示例7: Enemy
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public Enemy(final Application APP, TextureAtlas.AtlasRegion normalTexture, TextureAtlas.AtlasRegion hitTexture, Sprite redBar, Sprite greenBar, int BOUNDING_X, int BOUNDING_Y, int BOUNDING_WIDTH, int BOUNDING_HEIGHT)
{
this.normalTexture = normalTexture;
this.hitTexture = hitTexture;
this.sprite = new Sprite(normalTexture);
squishSFX = APP.assets.get("sounds/squish.wav", Sound.class);
velocity = new Vector2();
position = new Vector2();
forwardVelocity = new Vector2();
bounds = new Polygon();
healthBar = new HealthBar(redBar, greenBar);
this.BOUNDING_X = BOUNDING_X;
this.BOUNDING_Y = BOUNDING_Y;
this.BOUNDING_WIDTH = BOUNDING_WIDTH;
this.BOUNDING_HEIGHT = BOUNDING_HEIGHT;
vertices = new float[]{
0, 0,
0, BOUNDING_HEIGHT,
BOUNDING_WIDTH, BOUNDING_HEIGHT,
BOUNDING_WIDTH, 0};
bounds.setVertices(vertices);
bounds.setPosition(sprite.getX(), sprite.getY());
position.set(this.sprite.getX(), this.sprite.getY());
bounds.setOrigin(BOUNDING_WIDTH / 2, BOUNDING_HEIGHT / 2);
}
示例8: rectangleToPolygon
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public static Polygon rectangleToPolygon(Rectangle rectangle) {
Polygon polygon = new Polygon();
polygon.setOrigin(0, 0);
polygon.setPosition(rectangle.x, rectangle.y);
polygon.setVertices(new float[] { 0, 0, 0 + rectangle.width, 0,
0 + rectangle.width, 0 + rectangle.height, 0,
0 + rectangle.height });
return polygon;
}
示例9: Engine
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public Engine(int windowWidth, int windowHeight)
{
rand = new Random();
playerTex = new Texture(Gdx.files.internal("player.png"));
playerBulletTex = new Texture(Gdx.files.internal("Player lazer.png"));
enemyTex = new Texture(Gdx.files.internal("Fighter.png"));
chargerTex = new Texture(Gdx.files.internal("Charge.png"));
enemyBulletTex = new Texture(Gdx.files.internal("Figher lazer.png"));
playerSprite = new Sprite(playerTex);
playerBulletSprite = new Sprite(playerBulletTex);
enemySprite = new Sprite(enemyTex);
chargerSprite = new Sprite(chargerTex);
enemyBulletSprite = new Sprite(enemyBulletTex);
enemySprite.setOrigin(29.0f, 12.5f);
Position playerPos = new Position(windowWidth / 2, windowHeight / 2);
Velocity playerVel = new Velocity(0.0, 0.0);
Health health = new Health(10);
Invincibility inv = new Invincibility();
Entity player = addPlayer(playerPos, playerVel, health, inv);
Position enemyPos = new Position(windowWidth / 4, windowHeight / 4);
Velocity enemyVel = new Velocity(0.0, 0.0);
Direction enemyDir = new Direction(0.0, 1.0);
Enemy enemyComp = new Enemy(2, Enemy.SHOOTER);
Health enemyHealth = new Health(10);
Graphics enemyGraph= new Graphics(enemySprite);
float[] shooterCoords = {
0.0f, 0.0f,
58.0f, 0.0f,
29.0f, 25.0f
};
Polygon enemyPoly = new Polygon(shooterCoords);
enemyPoly.setOrigin(29.0f, 12.5f);
CollisionBox enemyBox = new CollisionBox(enemyPoly);
Entity enemy = addEnemy(enemyPos, enemyVel, enemyDir, enemyComp, enemyHealth, enemyGraph, enemyBox);
Signal<Boolean> signal = new Signal<Boolean>();
ControlSystem controls = new ControlSystem(0, player, this, signal);
AiSystem ai = new AiSystem(1, this, player);
MovementSystem movements = new MovementSystem(2);
EnemyCollisionSystem enemyCollisions = new EnemyCollisionSystem(3, player, this);
InvincibilitySystem invincible = new InvincibilitySystem(4, player);
PlayerBulletCollisionSystem pbc = new PlayerBulletCollisionSystem(5, this);
EnemyBulletCollisionSystem ebc = new EnemyBulletCollisionSystem(6, this, player);
SpawnSystem spawns = new SpawnSystem(7, this, player);
GraphicsSystem graphics = new GraphicsSystem(10, windowWidth, windowHeight, 1);
signal.add(movements);
addSystem(graphics);
addSystem(movements);
addSystem(enemyCollisions);
addSystem(invincible);
addSystem(pbc);
addSystem(ebc);
addSystem(controls);
addSystem(spawns);
addSystem(ai);
addEntity(enemy);
addEntity(player);
}
示例10: getPolygon
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* WARNING: EXPENSIVE OPERATION USE ONLY IN INITIALISATION STEPS
* This method is used to create a new rectangular polygon
*
* @param x the x coordinate of the polygon
* @param y the y coordinate of the polygon
* @param width the width of the polygon
* @param height the height of the polygon
* @return the created polygon
*/
public static Polygon getPolygon(float x, float y, float width, float height) {
float vals[] = {0, 0, width, 0, width, height, 0, height};
Polygon p = new Polygon();
p.setOrigin(width / 2, height / 2);
p.setScale(1, 1);
p.setVertices(vals);
p.setPosition(x, y);
return p;
}