Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java导入精灵_Java_Sprite - Fatal编程技术网

java导入精灵

java导入精灵,java,sprite,Java,Sprite,我正在设计一款游戏,允许玩家躲避落在他们身上的物体,但我不知道如何让精灵落在玩家身上。我有冰柱掉落,但我不知道如何让精灵/图像掉落。这是如何做到的 常数: public static final float ICICLES_HEIGHT = 1.0f; public static final float ICICLES_WIDTH = 0.5f; public static final Vector2 ICICLES_ACCELERATION = new Vector2(0, -

我正在设计一款游戏,允许玩家躲避落在他们身上的物体,但我不知道如何让精灵落在玩家身上。我有冰柱掉落,但我不知道如何让精灵/图像掉落。这是如何做到的

常数:

public static final float ICICLES_HEIGHT = 1.0f;
    public static final float ICICLES_WIDTH = 0.5f;
    public static final Vector2 ICICLES_ACCELERATION = new Vector2(0, -5.0f);
    public static final Color ICICLE_COLOR = Color.WHITE;
冰柱:

package com.udacity.gamedev.icicles;

import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;

public class Icicle {

    public static final String TAG = Icicle.class.getName();

    Vector2 position;
    Vector2 velocity;

    public Icicle(Vector2 position) {
        this.position = position;
        this.velocity = new Vector2();
    }

    public void update(float delta) {
        velocity.mulAdd(Constants.ICICLES_ACCELERATION, delta);
        position.mulAdd(velocity, delta);
    }

    public void render(ShapeRenderer renderer) {
        renderer.triangle(
                position.x, position.y,
                position.x - Constants.ICICLES_WIDTH / 2, position.y + Constants.ICICLES_HEIGHT,
                position.x + Constants.ICICLES_WIDTH / 2, position.y + Constants.ICICLES_HEIGHT
        );
    }
}
冰柱:

package com.udacity.gamedev.icicles;

import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.DelayedRemovalArray;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.udacity.gamedev.icicles.Constants.Difficulty;


public class Icicles {

    public static final String TAG = Icicles.class.getName();

    Difficulty difficulty;

    int iciclesDodged;
    DelayedRemovalArray<Icicle> icicleList;
    Viewport viewport;

    public Icicles(Viewport viewport, Difficulty difficulty) {
        this.difficulty = difficulty;
        this.viewport = viewport;
        init();
    }

    public void init() {
        icicleList = new DelayedRemovalArray<Icicle>(false, 100);
        iciclesDodged = 0;
    }

    public void update(float delta) {
        if (MathUtils.random() < delta * difficulty.spawnRate) {
            Vector2 newIciclePosition = new Vector2(
                    MathUtils.random() * viewport.getWorldWidth(),
                    viewport.getWorldHeight()
            );
            Icicle newIcicle = new Icicle(newIciclePosition);
            icicleList.add(newIcicle);
        }

        for (Icicle icicle : icicleList) {
            icicle.update(delta);
        }

        icicleList.begin();
        for (int i = 0; i < icicleList.size; i++) {
            if (icicleList.get(i).position.y < -Constants.ICICLES_HEIGHT) {
                iciclesDodged += 1;
                icicleList.removeIndex(i);
            }
        }
        icicleList.end();
    }

    public void render(ShapeRenderer renderer) {
        renderer.setColor(Constants.ICICLE_COLOR);
        for (Icicle icicle : icicleList) {
            icicle.render(renderer);
        }
    }
}
package com.udacity.gamedev.icicles;
导入com.badlogic.gdx.graphics.glutils.shaperender;
导入com.badlogic.gdx.math.MathUtils;
导入com.badlogic.gdx.math.Vector2;
导入com.badlogic.gdx.utils.DelayedRemovalArray;
导入com.badlogic.gdx.utils.viewport.viewport;
导入com.udacity.gamedev.icicles.Constants.constands;
公共级冰柱{
public static final String TAG=Icicles.class.getName();
难度;
国际ICIClesModed;
DelayedRemovalArray-icicleList;
视口;
公共冰柱(视口,难度){
这个。困难=困难;
this.viewport=视口;
init();
}
公共void init(){
icicleList=新的DelayedRemovalArray(false,100);
iciclesDodged=0;
}
公共无效更新(浮动增量){
if(MathUtils.random()
在icicles对象的更新方法中,您需要不断更新该icicles的Y坐标。我记得左下角被认为是(0,0)。所以你需要减少冰柱的y坐标


我假设您能够在窗口顶部渲染它。只需在主游戏循环中不断减小该对象的Y。此外,您还需要在游戏循环中调用渲染。

在冰柱对象的更新方法中,您需要不断更新该冰柱的Y坐标。我记得左下角被认为是(0,0)。所以你需要减少冰柱的y坐标


我假设您可以在窗口顶部渲染。只需在主游戏循环中不断减小该对象的Y值。您还需要在游戏循环中调用渲染。

您只需要重力。您只需要重力。谢谢。但我可以将冰柱从掉落改为图像掉落吗?您只需渲染和更新图像即可在游戏循环中的位置。为了让图像倒下谢谢,但是我可以把冰柱从倒下改为图像倒下吗?你只需要在游戏循环中渲染和更新图像的位置。为了让图像倒下