LlibGDX中两点之间的动画

时间:2020-07-31 00:52:51

标签: java libgdx box2d

我正在libGdx中做第一场比赛。我想让身体在两个固定点之间建立动画 我希望它能以恒定速度在2个固定点之间进行动画制作的敌军职业


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.World;
import static com.mohamed.vf.VirusFighters.PPM;

/**
 *
 * @author User
 */
public class enemy { 
    public int x;
    public Vector2 startPt ;
public Vector2 endPt ;
public Vector2 movingPt ;
    
    public World world;
        public Body mbody;
        public enem(World world){
            this.world=world;
            definePlayer();
           
           // update( delta );
            
        }

    public void definePlayer() {
        BodyDef bdef=new BodyDef();
        bdef.position.set(580/PPM,1140/PPM);
       
        bdef.type=BodyDef.BodyType.DynamicBody;
        mbody=world.createBody(bdef);
        
        FixtureDef mfdef=new FixtureDef();
        CircleShape shape=new CircleShape();
        shape.setRadius(10/PPM);
        mfdef.shape=shape;
         
        mbody.createFixture(mfdef);
        world.step(Gdx.app.getGraphics().getDeltaTime(), 6, 2);
            mbody.setLinearVelocity(new Vector2(new Vector2(580,590)));
        float x = mbody.getWorldCenter().x;
    }

}

这是我在PlayScreen类中声明要制作的函数

public void moveEnemey(float dt){

 enem.mbody.applyForce(new Vector2(-this.XFORCE,1), enemy.mbody.getWorldCenter(),true);
    enem.mbody.applyForce(new Vector2(this.XFORCE,1), enemy.mbody.getWorldCenter(),true);
    }

0 个答案:

没有答案