Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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
随机位置libgdx的持续时间_Libgdx_Duration - Fatal编程技术网

随机位置libgdx的持续时间

随机位置libgdx的持续时间,libgdx,duration,Libgdx,Duration,我正试图用libgdx做一个游戏,但a有一个问题。我搜索得很好,但找不到解决办法 我尝试将角色的随机位置设置为数组的最后一个位置到每个“渲染”中,角色必须具有数组的随机位置 问题是角色的位置不会持续, 我要的是每一秒都有“渲染”。 我试图制作一个动画,但它不适用于随机位置。 例如,如果我定义了位置(100100),它就会工作,每个字符图像保持1秒 我不知道你是否理解我,但我想要的是角色在数组的每个位置(随机位置)停留1秒 这是我的代码: public class MainScreen imple

我正试图用libgdx做一个游戏,但a有一个问题。我搜索得很好,但找不到解决办法

我尝试将角色的随机位置设置为数组的最后一个位置
到每个“渲染”中,角色必须具有数组的随机位置

问题是角色的位置不会持续, 我要的是每一秒都有“渲染”。 我试图制作一个动画,但它不适用于随机位置。 例如,如果我定义了位置(100100),它就会工作,每个字符图像保持1秒

我不知道你是否理解我,但我想要的是角色在数组的每个位置(随机位置)停留1秒

这是我的代码:

public class MainScreen implements Screen {

SpriteBatch batch;
private Texture carte;
private Texture mario;
private Array<Rectangle>foret;
private Animation animation;
private float time;
private Rectangle mari;
private Vector2 position;
private Rectangle mickey ; 
Game game;
public MainScreen(Game game) {
    this.game = game;
    batch = new SpriteBatch();
    carte = new Texture(Gdx.files.internal("foret.png"));

    animation = new Animation(3/3f , new TextureRegion(new Texture("mario1.png")) , new TextureRegion(new Texture("mario2.png")) , new TextureRegion(new Texture("mario3.png")));

    foret = new Array<Rectangle>();

}


public void carte(){
    foret = new Array<Rectangle>();
    for(int i =0 ; i<7 ; i++){
        for(int j =0 ; j<7 ; j++){
            Rectangle fore = new Rectangle();
            fore.x = (i*100)+100;
            fore.y = (j*50)+20 ;
            fore.width = 64;
            fore.height = 64;
            foret.add(fore);
            batch.draw(carte ,fore.x , fore.y , 64 , 64 );
        }
    }
}
public Rectangle depMarioRandom(){
    foret = new Array<Rectangle>();
    for(int i =0 ; i<7 ; i++){
        for(int j =0 ; j<7 ; j++){
            Rectangle fore = new Rectangle();
            fore.x = (i*100)+100;
            fore.y = (j*50)+20 ;
            fore.width = 64;
            fore.height = 64;
            foret.add(fore);
        }}
    int random = (int) ( Math.random() * foret.size );
    Rectangle randomX = foret.get(random);
     return randomX;

}

@Override
public void show() {


}
@Override
public void render(float delta) {

    Gdx.gl.glClearColor(1, 1, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


    this.mari = depMario();
    time += delta;
    Vector2 position = new Vector2(this.mari.x, this.mari.y);

      // i try te do a copy and scaling whith time but it doesn't work

    position.cpy().scl(time);

    batch.begin();
    carte();

    batch.draw(animation.getKeyFrame(time), position.x, position.y, 64, 64);
    animation.setPlayMode(Animation.PlayMode.LOOP);


    batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {

}
}
public类主屏幕实现屏幕{
喷雾批;
私人纹理点菜;
私人纹理马里奥;
私人Arrayforet;
私人动画;
私人浮动时间;
私人住宅;
私有向量2位置;
列兵米奇;
游戏;
公共主屏幕(游戏){
这个游戏=游戏;
批次=新的SpriteBatch();
carte=新纹理(Gdx.files.internal(“foret.png”);
动画=新动画(3/3f,新纹理区域(新纹理(“mario1.png”))、新纹理区域(新纹理(“mario2.png”)、新纹理区域(新纹理(“mario3.png”));
foret=新数组();
}
公共无效单(){
foret=新数组();

对于(int i=0;i我已经多次阅读了你的问题,这就是我所理解的

你想让你的角色有一个持续一秒的时间,你可以这样做

 counterTime += Gdx.graphic.getDeltaTime();
        time += delta;
        if(counterTime > 1 ) {// each second ==> one call to position random
            // putting the random position here
            position = new Vector2(this.mari.x, this.mari.y);
            counterTime = 0; // reset to 0;
        }

    // do not scall anything


    batch.begin();
    carte();
如果还有什么,请留言

祝你好运

编辑:


但是您只需要在create()方法中第一次初始化位置

我已经多次阅读了您的问题,这就是我的理解

你想让你的角色有一个持续一秒的时间,你可以这样做

 counterTime += Gdx.graphic.getDeltaTime();
        time += delta;
        if(counterTime > 1 ) {// each second ==> one call to position random
            // putting the random position here
            position = new Vector2(this.mari.x, this.mari.y);
            counterTime = 0; // reset to 0;
        }

    // do not scall anything


    batch.begin();
    carte();
如果还有什么,请留言

祝你好运

编辑:


但是您只需要在create()中第一次初始化位置[强>方法<

强>强>方法

拳头感谢你的答案,但不是你的拳头感谢你的答案,但你的答案,但不是你的拳头感谢你的答案,但不是你的答案,但不是我的不是我的不是我正在寻找的东西,我想我的特征,我想我的特征,我想我想我的特征,我想我的特征,留在位置,1秒,2次,2次,不知道我不确定你是否了解你是否了解你是否了解你了解你了解你的了解你的了解你的了解,你的了解你的信信信信信信信你的信你的信信你的信信你的信信你的信信你的信信你的信信你的信信信你方方,对你对你的信信信信你的信信信信信信信信信信信你的甲甲甲甲护护护护护护护护护护护护护护护护护护护护护护护护护护护护护护㶤㶤㶤㶤㶤㶤㶤㶤㶤㶤و在15 15 15 15 15 15 15半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半在本周四的半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半me:::我是一名高级管理人员(随机)在舞台和躺椅上休息(工作人员)第二步和第二步将取代一个单独的位置和休息时间。第二步和第三步将是一个随机的位置!!!你知道吗,内特罗先生,你知道吗,我知道你是谁,我知道你是谁回答,这样试试(我说英语,这样其他人可以从中受益),请告诉我它是否有效,祝你好运,我提供的解决方案是设置一个计数器,一秒钟后将mario的随机位置设置为零,这样radom位置将每秒钟调用一次,只需在c中第一次初始化该位置reate()1.感谢你的回答,但不是我正在寻找的我想要我的特征,我想我的特征,停留在位置上,1秒,2秒,1秒,1秒,1秒,无移动,移动!我不确定你是否了解你是否了解你是否了解你是否了解你是否理解你是否理解你了解MesasasasasasasasalamomoamamamamaramsasasasasalemomomomomomomomemememememememesasasasasasasasasasasaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMaMeMeMeMeMeMeMeMeMeMeMeMeMeMeMeMeMeMeMeMeMe了解,先生先生Netero先生Neteroo先生Neteroo先生Neteroo先生Neteroo先生((15)在在在在在你方方方方方方方方方,在在,在,在在在س在本月15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半半在2015年5月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月月日日日日日日日日日日日日日日日日日日日日日日日日日日日日日,,,,,在在在在在在上,在在在在上,在在在在在上的15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15日日日日日日日日日日日日日日日日日日日日3.我是法兰西大学的学生。瞧,我的问题是:我是一名高级管理人员舞台上的装饰(随机)和座位上的装饰(人员)第二步和第二步将取代一个单独的位置和休息时间。第二步和第三步将是一个随机的位置!!!你知道吗,内特罗先生,你知道吗,我知道你是谁,我知道你是谁回答,这样试试(我说英语,这样其他人可以从中受益),请告诉我它是否有效,祝你好运,我提供的解决方案是设置一个计数器,一秒钟后将mario的随机位置设置为零,这样radom位置将每秒钟调用一次,只需在c中第一次初始化该位置方法或只是将计数器时间初始化为值>1