本文整理匯總了Java中com.badlogic.gdx.math.Vector2類的典型用法代碼示例。如果您正苦於以下問題:Java Vector2類的具體用法?Java Vector2怎麽用?Java Vector2使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Vector2類屬於com.badlogic.gdx.math包,在下文中一共展示了Vector2類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: pinch
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
@Override
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
if(control.getInput().recipe == null && !control.getInput().breakMode.lockCamera)
return false;
if(pinch1.x < 0){
pinch1.set(initialPointer1);
pinch2.set(initialPointer2);
}
Vector2 vec = (vector.set(pointer1).add(pointer2).scl(0.5f)).sub(pinch1.add(pinch2).scl(0.5f));
player.x -= vec.x*Core.camera.zoom/Core.cameraScale;
player.y += vec.y*Core.camera.zoom/Core.cameraScale;
pinch1.set(pointer1);
pinch2.set(pointer2);
return false;
}
示例2: create
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
/**
* 創建限定雙方向速度的限製器
*
* @param limitX (limitX >= 0)
* @param limitY (limitY >= 0)
* @return
*/
public static VelocityLimitListener create(final float limitX, final float limitY) {
return new VelocityLimitListener() {
@Override
public void onVelocity(Vector2 velocity) {
if(velocity.y > limitY) {
velocity.y = limitY;
} else if(velocity.y < -limitY) {
velocity.y = -limitY;
}
if(velocity.x > limitX) {
velocity.x = limitX;
} else if(velocity.x < -limitX) {
velocity.x = -limitX;
}
}
};
}
示例3: getYmax
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
public float getYmax() {
float ymax=-1;
if (arrayAttachers.length > 7) {
ymax = arrayAttachers[6].findActor("frame").localToStageCoordinates(new Vector2(0, 0)).y;
ymax = ymax + arrayAttachers[6].findActor("frame").getWidth() * 0.5f;
} else {
if(arrayAttachers.length>0)
ymax = arrayAttachers[arrayAttachers.length - 1].findActor("frame").localToStageCoordinates(new Vector2(0, 0)).y;
if (arrayAttachers.length < 4 && arrayAttachers.length > 0)
ymax = ymax + arrayAttachers[arrayAttachers.length - 1].findActor("frame").getHeight();
else if (arrayAttachers.length > 3)
ymax = ymax + arrayAttachers[arrayAttachers.length - 1].findActor("frame").getHeight() * 0.8f;
else if (arrayAttachers.length > 5)
ymax = ymax + arrayAttachers[arrayAttachers.length - 1].findActor("frame").getHeight() * 0.5f;
}
return ymax;
}
示例4: createCoinEntity
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
public void createCoinEntity(float x, float y, int moneyValue) {
Entity entity = new Entity();
OffsetComponent ocomp = new OffsetComponent(16, 16);
SkeletonComponent scomp = new SkeletonComponent(Assets.coinSkeleton);
TimeComponent tcomp = new TimeComponent(0.5f);
VelocityComponent vcomp = new VelocityComponent(25f);
PositionComponent pcomp = new PositionComponent(new Vector2(x, y));
MoneyComponent mcomp = new MoneyComponent(moneyValue);
RenderableComponent rcomp = new RenderableComponent();
scomp.animationState.setData(Assets.coinAnimationState.getData());
entity.add(pcomp)//
.add(vcomp)//
.add(tcomp)//
.add(scomp)//
.add(ocomp)//
.add(mcomp)//
.add(rcomp);
_engine.addEntity(entity);
}
示例5: part3
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
public void part3() {
Entity proj = BaseProjectile.Create(new Vector2(MathUtils.random(0, 560), 720), BulletType.FormCircleLightM, MathUtils.randomBoolean() ? BulletType.ColorOrange : BulletType.ColorBlue);
final Transform ptransform = proj.GetComponent(Transform.class);
proj.AddComponent(new MoveFunction(MoveFunctionTarget.ACCEL, MoveFunctionType.ASSIGNMENT, new IMoveFunction() {
int flag = 2;
int bounce = MathUtils.random(250, 500);
@Override
public Vector2 getTargetVal(int time) {
if (flag > 0 && Math.abs(ptransform.position.y - bounce) < 30) {
final int m = flag * 8;
flag--;
bounce -= 90;
return vct2_tmp1.set(0.001f, m);
}
return vct2_tmp1.set(0.001f, -0.1f);
}
}));
proj.AddComponent(new EnemyJudgeCircle(15));
}
示例6: setPositionPercent
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
/**
* Set the percent(x,y) of the widget in OpenGL coordinates
*
* @param percent The percent (x,y) of the widget in OpenGL coordinates
*/
public void setPositionPercent(Vector2 percent) {
if (_usingLayoutComponent) {
LayoutComponent component = this.getOrCreateLayoutComponent();
component.setPositionPercentX(percent.x);
component.setPositionPercentY(percent.y);
component.refreshLayout();
}
else
{
_positionPercent.set(percent);
if (_running){
Widget widgetParent = getWidgetParent();
if (widgetParent != null) {
Size parentSize = widgetParent.getContentSize();
setPosition(Math.abs(parentSize.width * _positionPercent.x), Math.abs(parentSize.height * _positionPercent.y));
}
}
}
}
示例7: createRevoluteJoint
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
/**
* create Revolute Joint
*/
public RevoluteJoint createRevoluteJoint(Body bodyA, Body bodyB,
Vector2 jointPositionA, Vector2 jointPositionB,
boolean enabledMotor, int maxMotorTorque, int motorSpeed) {
RevoluteJointDef rJoint = new RevoluteJointDef();
rJoint.bodyA = bodyA;
rJoint.bodyB = bodyB;
rJoint.localAnchorA.set(jointPositionA.x * WORLD_TO_BOX,
jointPositionA.y * WORLD_TO_BOX);
rJoint.localAnchorB.set(jointPositionB.x * WORLD_TO_BOX,
jointPositionB.y * WORLD_TO_BOX);
rJoint.enableMotor = enabledMotor;
rJoint.maxMotorTorque = maxMotorTorque;
rJoint.motorSpeed = motorSpeed;
RevoluteJoint joint = (RevoluteJoint) world.createJoint(rJoint);
return joint;
}
示例8: handleCollision
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
@Override public void handleCollision(Ball ball, Body bodyHit, Field field) {
if (retractWhenHit) {
this.setRetracted(true);
}
if (killBall) {
field.removeBall(ball);
}
else {
Vector2 impulse = this.impulseForBall(ball);
if (impulse!=null) {
ball.applyLinearImpulse(impulse);
flashForFrames(3);
}
}
}
示例9: draw
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
private void draw(int x, int y, EntityType entityType) {
switch (entityType) {
case ALIEN:
planetCreationSystem.spawnDude(x, y).massInverse(true).alien();
break;
case ICBM:
cardScriptSystem.spawnStructure("icbm", G.LAYER_STRUCTURES_FOREGROUND)
.explosiveYield(MathUtils.random(5,10)).pos(x, y);
break;
case SKYSCRAPER:
cardScriptSystem.spawnStructure("skyscraper" + MathUtils.random(7), G.LAYER_STRUCTURES_BACKGROUND).pos(x, y);
break;
case DOLPHIN:
E e = planetCreationSystem.spawnDude(x, y);
Vector2 gravityVector = v.set(e.planetboundGravity()).rotate(180f);
e
.dolphinized()
.physicsVr(1000f)
.physicsVx(gravityVector.x * 100f)
.physicsVy(gravityVector.y * 100f);
break;
case DUDE:
planetCreationSystem.spawnDude(x, y).orientToGravityIgnoreFloor(false);
break;
}
}
示例10: show
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
@Override
public void show() {
super.show();
Entity characterSelectScreenEntity = Entity.Create();
Entity selectCharacter = Entity.Create();
characterSelectScreenEntity.AddComponent(new Transform(new Vector2(480, 360)));
selectCharacter.AddComponent(new Transform(new Vector2(600, 600)));
characterSelectScreenEntity.AddComponent(new ImageRenderer(ResourceManager.textures.get("CharacterSelect"), 0));
selectCharacter.AddComponent(new ImageRenderer(ResourceManager.textures.get("SelectCharacter"), 1));
KeyboardSelectable selectable = new KeyboardSelectable(() -> {
GameMain.instance.setScreen(new FightScreen());
});
selectable.isSelected = true;
selectCharacter.AddComponent(selectable);
}
示例11: Character
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
public Character() {
this.cooldownTimer = new float[5];
this.castTimer = new float[5];
this.casting = new boolean[5];
this.extraData = new Object[5];
this.cooldowns = new float[5];
this.costs = new float[5];
this.random = new Random();
finishedAttack = true;
vectorPool = new Pool<Vector2>() {
@Override
protected Vector2 newObject() {
return new Vector2();
}
@Override
protected void reset(Vector2 object) {
object.setZero();
}
};
}
示例12: Intersect
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
/**相交測試
* 多邊形與AABB
* @param A
* @param B
* @param MTD
* @return */
public static final boolean Intersect(final Polygon A,final AABBShape B,
final Vector2 positionA, final Vector2 positionB){
axisX.set(1,0);
axisY.set(0,1);
Vector2 tempE=null;
//用這個不用單獨求0的情況
for(int j=A.getPoints().length-1, i=0; i<A.getPoints().length;
j=i, i++) {
tempE=A.getPoints()[i].sub(A.getPoints()[j]);
if (axisSeparatePolygonsMTD(new Vector2(-tempE.y, tempE.x), A, B, positionA, positionB))
return false;
}
if (axisSeparatePolygonsMTDX(axisX, A, B, positionA, positionB))
return false;
if (axisSeparatePolygonsMTDY(axisY, A, B, positionA, positionB))
return false;
return true;
}
示例13: circleToSquare
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
/**
* Because the algorithm is based on vertices, and the circles do not have vertices, we create a square around it.
* @param fixture Circle fixture
* @return A square instead of the circle
*/
private static PolygonShape circleToSquare(Fixture fixture) {
Vector2 position = fixture.getBody().getLocalCenter();
float x = position.x;
float y = position .y;
float radius = fixture.getShape().getRadius();
PolygonShape octagon = new PolygonShape();
Vector2[] vertices = new Vector2[4];
vertices[0] = new Vector2(x-radius, y+radius);
vertices[1]= new Vector2(x+radius, y+radius);
vertices[2]= new Vector2(x-radius, y-radius);
vertices[3]= new Vector2(x+radius, y-radius);
octagon.set((Vector2[]) vertices);
return octagon;
}
示例14: PlayState
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
public PlayState(GameStateManager gsm) {
super(gsm);
font = new BitmapFont();
font.setColor(1.0f, 1.0f, 1.0f, 1.0f);
bird = new Bird(50, 300);
camera.setToOrtho(false, FlappyBaran.WIDTH / 2, FlappyBaran.HEIGHT / 2);
bg = new Texture("backgrnd.jpg");
ground = new Texture("ground.png");
groundPos1 = new Vector2(camera.position.x - camera.viewportWidth / 2, GROUND_Y_OFFSET);
groundPos2 = new Vector2((camera.position.x - camera.viewportWidth / 2) + ground.getWidth(), GROUND_Y_OFFSET);
tubes = new Array<com.kirdmiv.flappybaranus.sprites.Tube>();
for (int i = 0; i < TUBE_COUNT; i++){
tubes.add(new com.kirdmiv.flappybaranus.sprites.Tube(i * (TUBE_SPACING + com.kirdmiv.flappybaranus.sprites.Tube.TUBE_WIDTH)));
}
}
示例15: PointApplyAffineTransform
import com.badlogic.gdx.math.Vector2; //導入依賴的package包/類
/**Multiply point (x,y,1) by a affine transform.
* @return <b>stack object </b>*/
public static final Vector2 PointApplyAffineTransform(final Vector2 point, final AffineTransform t) {
Vector2 p = stackVec2;
p.x = (t.a * point.x + t.c * point.y + t.tx);
p.y = (t.b * point.x + t.d * point.y + t.ty);
return p;
}