【问题标题】:Android Studio, LibGDX auto-increase speed after certain time has passedAndroid Studio,LibGDX在一定时间后自动增加速度
【发布时间】:2016-06-15 21:07:07
【问题描述】:

我正在做一个项目,我正在学习 LibGDX,但到目前为止,该项目进展顺利,但是,教程没有说明如何在经过一定时间后提高速度,例如(10秒过去了,我希望我的敌人将速度提高到 0.1f,这意味着 10%,再过 10 秒后,自动将速度提高到 0.2f,依此类推。)这是我代码的唯一部分需要改变以使他们的敌人提高他们的速度public static final Vector2 ENEMY_LINEAR_VELOCITY = new Vector2(-10f, 0);教程在这里('http://williammora.com/a-running-game-with-libgdx-part-1/')我该怎么做?有人可以帮我吗?我将不胜感激!

常量类:

package com.avoidcrashjump;

import com.badlogic.gdx.math.Vector2;


/**
 * Created by Felipe on 2/29/2016.
 */
public class Constants {
    public static final int APP_WIDTH = 1024;
    public static final int APP_HEIGHT = 640;

    public static final Vector2 WORLD_GRAVITY = new Vector2(0, -10);

    public static final float GROUND_X = 0;
    public static final float GROUND_Y = 0;
    public static final float GROUND_WIDTH = 50f;
    public static final float GROUND_HEIGHT = 2f;
    public static final float GROUND_DENSITY = 0f;
    public static final float PLAYER_X = 2;
    public static final float PLAYER_Y = GROUND_Y + GROUND_HEIGHT;
    public static final float PLAYER_WIDTH = 1f;
    public static final float PLAYER_HEIGHT = 1f;
    public static final float PLAYER_GRAVITY_SCALE = 2.5f;
    public static float PLAYER_DENSITY = 0.5f;
    public static final float PLAYER_DODGE_X = 2f;
    public static final float PLAYER_DODGE_Y = 1.5f;
    public static final Vector2 PLAYER_JUMPING_LINEAR_IMPULSE = new Vector2(0,13f);
    public static final float PLAYER_HIT_ANGULAR_IMPULSE = 10f;
    public static final float ENEMY_X = 25f;
    public static final float ENEMY_DENSITY = PLAYER_DENSITY;
    public static final float RUNNING_SHORT_ENEMY_Y = 1.5f;
    public static final float RUNNING_LONG_ENEMY_Y = 2f;
    public static final float FLYING_ENEMY_Y = 3f;
    public static final Vector2 ENEMY_LINEAR_VELOCITY = new Vector2(-10f, 0);


}

【问题讨论】:

    标签: java android android-studio libgdx


    【解决方案1】:

    您的班级名为Constants,您的速度使用final 声明。类的名称告诉我们我们不应该尝试更改这些,final 不允许我们这样做。

    但是,如果您更改变量声明(将其移动到某处并删除 final 关键字)。要使其增加,您可以使用Gdx.graphics.getDeltaTime()

    创建一个变量来计算经过的时间:

    float timer = 0;
    

    然后在你的 render() 方法中

    timer += Gdx.graphics.getDeltaTime(); //returns time between two frames
    if(timer > 10) { //after 10 seconds
        speed = speed * 1.1F;
        timer = 0; //reset timer
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-06
      • 1970-01-01
      • 2019-08-05
      相关资源
      最近更新 更多