gpt4 book ai didi

java - Android Studio、LibGDX 在经过一定时间后自动提高速度

转载 作者:行者123 更新时间:2023-12-01 10:18:42 25 4
gpt4 key购买 nike

我正在制作一个项目,我正在学习 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);


}

最佳答案

您的类被命名为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
}

关于java - Android Studio、LibGDX 在经过一定时间后自动提高速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35756945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com