當前位置: 首頁>>代碼示例>>Java>>正文


Java Vector2類代碼示例

本文整理匯總了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;
}
 
開發者ID:Anuken,項目名稱:Mindustry,代碼行數:21,代碼來源:GestureHandler.java

示例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;
			}
		}
	};
}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:26,代碼來源:Base2D.java

示例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;
}
 
開發者ID:TudorRosca,項目名稱:enklave,代碼行數:18,代碼來源:DrawAttachers.java

示例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);
}
 
開發者ID:JoakimRW,項目名稱:ExamensArbeteTD,代碼行數:20,代碼來源:EntityFactory.java

示例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));
}
 
開發者ID:cn-s3bit,項目名稱:TH902,代碼行數:20,代碼來源:AIS1L4Boss.java

示例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));
            }
        }
    }
}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:25,代碼來源:Widget.java

示例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;
   }
 
開發者ID:game-libgdx-unity,項目名稱:GDX-Engine,代碼行數:22,代碼來源:PhysicsManager.java

示例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);
        }
    }
}
 
開發者ID:StringMon,項目名稱:homescreenarcade,代碼行數:17,代碼來源:WallElement.java

示例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;
    }
}
 
開發者ID:DaanVanYperen,項目名稱:odb-little-fortune-planet,代碼行數:27,代碼來源:DrawingSystem.java

示例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);
}
 
開發者ID:cn-s3bit,項目名稱:TH902,代碼行數:19,代碼來源:CharacterSelectScreen.java

示例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();
        }
    };
}
 
開發者ID:EtherWorks,項目名稱:arcadelegends-gg,代碼行數:24,代碼來源:Character.java

示例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;
}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:25,代碼來源:CollideAlgorithms.java

示例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;
}
 
開發者ID:jocasolo,項目名稱:water2d-libgdx,代碼行數:22,代碼來源:IntersectionUtils.java

示例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)));
    }
}
 
開發者ID:kirdmiv,項目名稱:Flappy-Baranus,代碼行數:18,代碼來源:PlayState.java

示例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;
 }
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:9,代碼來源:AffineTransform.java


注:本文中的com.badlogic.gdx.math.Vector2類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。