本文整理汇总了Java中com.badlogic.gdx.math.MathUtils.isZero方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.isZero方法的具体用法?Java MathUtils.isZero怎么用?Java MathUtils.isZero使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.math.MathUtils
的用法示例。
在下文中一共展示了MathUtils.isZero方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setHealth
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/**
* Setzt die Anzahl der Lebenspunkte direkt.
* Sollte so ehr selten benutzt werden.
*
* @see Player#applyDamage(int)
* @see Player#heal(int)
*
* @param health die neue Anzahl Lebenspunkte
*/
public void setHealth(int health) {
if (health > 100)
health = 100;
if (health < 0 || MathUtils.isZero(health))
{
if (cheatManager.isImmortal())
{
this.health = 100;
return;
}
health = 0;
if (deadCallback != null)
deadCallback.run();
}
this.health = health;
}
示例2: onUpdate
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
public void onUpdate(float deltaTime)
{
if (!MathUtils.isZero(hitTimer))
{
hitTimer -= deltaTime;
if (hitTimer <= 0f)
hitTimer = 0f;
}
body.setLinearVelocity(Vector2.Zero);
}
示例3: render
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
public void render(Batch batch, float deltaTime)
{
if (body == null) return;
Color oldColor = batch.getColor();
batch.setColor(1f, (health + 5)/10f, (health + 5)/10f, 1f);
Vector2 pos = body.getPosition();
pos.scl(Physics.PPM);
TextureRegion region = MathUtils.isZero(hitTimer) ? dummy : dummy_hit;
batch.draw(region, // TextureRegion (front, back, side)
pos.x - dummy.getRegionWidth() / 2, // Offset to the X position (character center)
pos.y, // Y position is at the foots
dummy.getRegionWidth() / 2, // Origin X (important for flipping)
dummy.getRegionHeight(), // Origin Y
dummy.getRegionWidth(), // Width
dummy.getRegionHeight(), // Height
1f, // Scale X (-1 to flip)
1f, // Scale Y
0f); // Rotation
batch.setColor(oldColor);
}
示例4: onUpdate
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
public void onUpdate(float deltaTime)
{
if (!MathUtils.isZero(hitTimer))
{
hitTimer -= deltaTime;
if (hitTimer <= 0f)
hitTimer = 0f;
}
if (attackTimer > 0f)
attackTimer -= deltaTime;
if (handler.canAttack())
{
if (attackTimer <= 0f)
{
attackTimer = 1.6f;
handler.attack(3);
}
}
bodyPosition = body.getPosition();
if (body.getLinearVelocity().sub(direction).len2() > 1 || (MathUtils.isEqual(oldPosition.x, bodyPosition.x) && MathUtils.isEqual(oldPosition.y, bodyPosition.y)))
{
direction.set(MathUtils.random(-1f, 1f), MathUtils.random(-1f, 1f));
direction.scl(4f);
}
oldPosition = bodyPosition;
body.applyForceToCenter(direction, true);
}
示例5: render
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/**
* Rendert das Objekt in die Map.
*
* @param batch der Batch der Map
* @param deltaTime die Zeit, die seit dem letzten Frame vergangen ist
*/
@Override
public void render(Batch batch, float deltaTime)
{
if (body == null) return;
Vector2 pos = body.getPosition();
pos.scl(Physics.PPM);
TextureRegion region = null;
float scaleX = 1f;
boolean notMoving = MathUtils.isZero(body.getLinearVelocity().x, 0.5f) && MathUtils.isZero(body.getLinearVelocity().y, 0.5f);
if (notMoving)
{
animationTime = 0f;
} else {
animationTime += deltaTime;
}
switch (orientation)
{
case LOOK_FORWARD:
region = notMoving ? npcFront : npcFrontWalk.getKeyFrame(animationTime);
break;
case LOOK_LEFT:
region = notMoving ? npcSide : npcSideWalk.getKeyFrame(animationTime);
scaleX = -1f;
break;
case LOOK_BACKWARD:
region = notMoving ? npcBack : npcBackWalk.getKeyFrame(animationTime);
scaleX = -1f;
break;
case LOOK_RIGHT:
region = notMoving ? npcSide : npcSideWalk.getKeyFrame(animationTime);
break;
}
batch.draw(region, // TextureRegion (front, back, side)
pos.x - npcSide.getRegionWidth() / 2, // Offset to the X position (character center)
pos.y, // Y position is at the foots
npcSide.getRegionWidth() / 2, // Origin X (important for flipping)
npcSide.getRegionHeight(), // Origin Y
npcSide.getRegionWidth(), // Width
npcSide.getRegionHeight(), // Height
scaleX, // Scale X (-1 to flip)
1f, // Scale Y
0f); // Rotation
}
示例6: applyDamage
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/**
* Fügt dem Spieler schaden zu.
*
* @param damage wie viele Lebenspunkte soll der Spieler verlieren?
*/
public void applyDamage(int damage) {
if (!MathUtils.isZero(damageTime)) return;
if (!cheatManager.isImmortal())
this.setHealth(health - damage);
damageTime = 0.1f * (float) damage;
}