Java Android Studio LibGDX中更新方法的问题

Java Android Studio LibGDX中更新方法的问题,java,android,android-studio,libgdx,Java,Android,Android Studio,Libgdx,我试图调用update方法,以便每次经过一定的时间后,它都会破坏并添加一个新的障碍,比如游戏循环。但是,当我这样做时,会出现以下一系列错误: Error:(146, 8) Gradle: error: illegal start of expression Error:(146, 16) Gradle: error: illegal start of expression Error:(146, 32) Gradle: error: ';' expected Error:(149, 23)

我试图调用update方法,以便每次经过一定的时间后,它都会破坏并添加一个新的障碍,比如游戏循环。但是,当我这样做时,会出现以下一系列错误:

Error:(146, 8) Gradle: error: illegal start of expression 
Error:(146, 16) Gradle: error: illegal start of expression 
Error:(146, 32) Gradle: error: ';' expected 
Error:(149, 23) Gradle: error: ';' expected 
Error:(151, 31) Gradle: error: '.class' expected 
Error:(151, 40) Gradle: error: illegal start of expression 
Error:(151, 41) Gradle: error: ';' expected
以下是导致问题的代码:

public void update(float deltaTime) {
        Texture playerTexture = game.getManager().get("player.png");
        Texture floorTexture = game.getManager().get("floor.png");
        Texture overfloorTexture = game.getManager().get("overfloor.png");
        Texture overfloor2Texture = game.getManager().get("overfloor2.png");
        Texture obstacleTexture = game.getManager().get("obstacle.png");
        Texture obstacle2Texture = game.getManager().get("obstacle2.png");

        float timer = 0;
        float spawnTime = 4f;
        private void spawnEntity();
        {
            //Increment timer by the duration since the previous frame
            float timer += Gdx.graphics.getRawDeltaTime();
            //Compare to spawntime
            if (timer >= float spawnTime)
            {
                //Spawn your object
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture, 0, 1000, 1));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,8, 10 ,5));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,10, 10 ,8));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,34 , 3 ,5));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,19 , 8 ,4));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,24 , 8 ,1.5f));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,27 , 5 , 2));
                obstacleList.add(new ObstacleEntity(world, floorTexture, overfloorTexture, overfloor2Texture ,25, 10 ,20));
                //But you will probably want to spawn something on the right, just outside of your screen view.

                //This is the right side of your vp in the world. Depending how you draw you can add some more to it.
                float spawnX = camera.position.x + camera.viewportWidth / 2;
                //Then use this to spawn your object, since you hardcoded stuff I have no idea where to put it.

                //Now reset timer
                timer-= spawnTime;

                //And perhaps randomize the spawnTime? (between 2 and 4 seconds)
                Random random;
                spawnTime = random.nextFloat() * 2 + 2;
            }
        }
以下是我的
GameScreen
课程的代码:

package com.circlecrashavoider;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.ContactImpulse;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.Manifold;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.circlecrashavoider.entities.FloorEntity;
import com.circlecrashavoider.entities.ObstacleEntity;
import com.circlecrashavoider.entities.ObstacleEntity2;
import com.circlecrashavoider.entities.PlayerEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;

/**
 * Created by Felipe on 2/22/2016.
 */

public class GameScreen extends BaseScreen {

    private Stage stage;

    private World world;

    private PlayerEntity player;

    private List<FloorEntity> floorList = new ArrayList<FloorEntity>();

    private List<ObstacleEntity> obstacleList = new ArrayList<ObstacleEntity>();

    private List<ObstacleEntity2> obstacle2List = new ArrayList<ObstacleEntity2>();

    public GameScreen(MainGame game) {
        super(game);
        stage = new Stage(new FitViewport(1024, 620));
        world = new World(new Vector2(0, -10), true);

        world.setContactListener(new ContactListener() {

            private boolean areCollided(Contact contact, Object userA, Object userB) {
                return (contact.getFixtureA().getUserData().equals(userA) && contact.getFixtureB().getUserData().equals(userB)) ||
                        (contact.getFixtureA().getUserData().equals(userB) && contact.getFixtureB().getUserData().equals(userA));
            }

            @Override
            public void beginContact(Contact contact) {
                if (areCollided(contact, "player", "floor")) {
                    player.setJumping(false);
                    if (Gdx.input.isTouched()) {
                        player.setMustJump(true);
                    }
                }

                if (areCollided(contact, "player", "obstacle")) {
                        player.setAlive(false);
                    System.out.println("GAME OVER");

                }

                if (areCollided(contact, "player", "obstacle2")) {
                    player.setAlive(false);
                    System.out.println("GAME OVER");
                }
            }

            @Override
            public void endContact(Contact contact) {

            }

            @Override
            public void preSolve(Contact contact, Manifold oldManifold) {

            }

            @Override
            public void postSolve(Contact contact, ContactImpulse impulse) {

            }
        });
    }

    @Override
    public void show() {
        Texture playerTexture = game.getManager().get("player.png");
        Texture floorTexture = game.getManager().get("floor.png");
        Texture overfloorTexture = game.getManager().get("overfloor.png");
        Texture overfloor2Texture = game.getManager().get("overfloor2.png");
        Texture obstacleTexture = game.getManager().get("obstacle.png");
        Texture obstacle2Texture = game.getManager().get("obstacle2.png");
        player = new PlayerEntity(world, playerTexture, new Vector2(1, 2));

        for (FloorEntity floor : floorList) {
            stage.addActor(floor);
        }
        for (ObstacleEntity obstacle : obstacleList) {
            stage.addActor(obstacle);
            stage.addActor(player);
        }
        for (ObstacleEntity2 obstacle2 : obstacle2List) {
            stage.addActor(obstacle2);
        }
    }

    public void update(float deltaTime) {
        Texture playerTexture = game.getManager().get("player.png");
        Texture floorTexture = game.getManager().get("floor.png");
        Texture overfloorTexture = game.getManager().get("overfloor.png");
        Texture overfloor2Texture = game.getManager().get("overfloor2.png");
        Texture obstacleTexture = game.getManager().get("obstacle.png");
        Texture obstacle2Texture = game.getManager().get("obstacle2.png");

        float timer = 0;
        float spawnTime = 4f;
        private void spawnEntity();
        {
            //Increment timer by the duration since the previous frame
            float timer += Gdx.graphics.getRawDeltaTime();
            //Compare to spawntime
            if (timer >= float spawnTime)
            {
                //Spawn your object
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture, 0, 1000, 1));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,8, 10 ,5));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,10, 10 ,8));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,34 , 3 ,5));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,19 , 8 ,4));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,24 , 8 ,1.5f));
                floorList.add(new FloorEntity(world, floorTexture, overfloorTexture,overfloor2Texture ,27 , 5 , 2));
                obstacleList.add(new ObstacleEntity(world, floorTexture, overfloorTexture, overfloor2Texture ,25, 10 ,20));
                //But you will probably want to spawn something on the right, just outside of your screen view.

                //This is the right side of your vp in the world. Depending how you draw you can add some more to it.
                float spawnX = camera.position.x + camera.viewportWidth / 2;
                //Then use this to spawn your object, since you hardcoded stuff I have no idea where to put it.

                //Now reset timer
                timer-= spawnTime;

                //And perhaps randomize the spawnTime? (between 2 and 4 seconds)
                Random random;
                spawnTime = random.nextFloat() * 2 + 2;
            }
        }

    @Override
    public void render(float delta) {
        Gdx.gl20.glClearColor(0.5f, 0.6f, 1, 3f);
        Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);

        stage.act();
        world.step(delta, 6 ,2);
        stage.draw();
    }

    @Override
    public void dispose() {
        stage.dispose();
        world.dispose();
    }
}
package com.circlecrashavoider;
导入com.badlogic.gdx.gdx;
导入com.badlogic.gdx.graphics.GL20;
导入com.badlogic.gdx.graphics.Texture;
导入com.badlogic.gdx.math.Vector2;
导入com.badlogic.gdx.physics.box2d.Contact;
导入com.badlogic.gdx.physics.box2d.contactpulse;
导入com.badlogic.gdx.physics.box2d.ContactListener;
导入com.badlogic.gdx.physics.box2d.Manifold;
导入com.badlogic.gdx.physics.box2d.World;
导入com.badlogic.gdx.scenes.scene2d.Stage;
导入com.badlogic.gdx.utils.viewport.FitViewport;
导入com.circlecrashavoider.entities.FloorEntity;
导入com.circlecrashavoider.entities.ObstacleEntity;
导入com.circlecrashavoider.entities.ObstacleEntity2;
导入com.circlecrashavoider.entities.PlayerEntity;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.Objects;
导入java.util.Random;
/**
*由Felipe于2016年2月22日创建。
*/
公共类GameScreen扩展BaseScreen{
私人舞台;
私人世界;
私人游戏者;
private List floorList=new ArrayList();
private List obstacleList=new ArrayList();
private List obstacle2List=new ArrayList();
公共游戏屏幕(主游戏){
超级(游戏);
阶段=新阶段(新阶段(1024620));
世界=新世界(新矢量2(0,-10),真);
setContactListener(新的ContactListener(){
私有布尔值冲突(联系人、对象userA、对象userB){
返回(contact.getFixtureA().getUserData().equals(userA)和&contact.getFixtureB().getUserData().equals(userB))||
(contact.getFixtureA().getUserData().equals(userB)和&contact.getFixtureB().getUserData().equals(userA));
}
@凌驾
public void beginContact(联系人){
如果(发生碰撞(联系“玩家”、“地板”)){
运动员.起跳(假);
if(Gdx.input.isTouched()){
player.setMustJump(true);
}
}
如果(发生碰撞(联系“玩家”、“障碍物”)){
player.setAlive(false);
System.out.println(“游戏结束”);
}
如果(发生碰撞(联系“玩家”、“障碍物”)){
player.setAlive(false);
System.out.println(“游戏结束”);
}
}
@凌驾
公共无效endContact(联系人){
}
@凌驾
公共无效预解(触点触点、歧管、歧管){
}
@凌驾
公共无效后处理(触点接触、触点脉冲){
}
});
}
@凌驾
公开展览({
纹理playerTexture=game.getManager().get(“player.png”);
纹理floorTexture=game.getManager().get(“floor.png”);
纹理overfloorTexture=game.getManager().get(“overfloor.png”);
纹理overfloor2Texture=game.getManager().get(“overfloor2.png”);
纹理obstacleTexture=game.getManager().get(“障碍物.png”);
纹理obstacle2Texture=game.getManager().get(“obstacle2.png”);
玩家=新玩家属性(世界,玩家文本,新向量2(1,2));
适用于(楼层性楼层:楼层列表){
舞台演员(现场);
}
for(障碍:障碍列表){
阶段。添加者(障碍);
舞台演员(演员);
}
for(ObstacleEntity2 obstacle2:obstacle2List){
舞台附加演员(障碍2);
}
}
公共无效更新(浮动增量时间){
纹理playerTexture=game.getManager().get(“player.png”);
纹理floorTexture=game.getManager().get(“floor.png”);
纹理overfloorTexture=game.getManager().get(“overfloor.png”);
纹理overfloor2Texture=game.getManager().get(“overfloor2.png”);
纹理obstacleTexture=game.getManager().get(“障碍物.png”);
纹理obstacle2Texture=game.getManager().get(“obstacle2.png”);
浮动计时器=0;
浮动时间=4f;
私有实体();
{
//从上一帧开始按持续时间递增计时器
float timer+=Gdx.graphics.getRawDeltaTime();
//与时间相比
如果(计时器>=浮动时间)
{
//生成你的对象
floorList.add(新的FloorRenty(世界,floorTexture,overfloorTexture,overfloor2Texture,0,1000,1));
floorList.add(新的FloorEntity(world,floorTexture,overfloorTexture,overfloor2Texture,8,10,5));
floorList.add(新的FloorRenty(世界,floorTexture,overfloorTexture,overfloor2Texture,10,10,8));
floorList.add(新的FloorEntity(world,floorTexture,overfloorTexture,overfloor2Texture,34,3,5));
floorList.add(新的FloorRenty(世界,floorTexture,overfloorTexture,overfloor2Texture,19,8,4));
floorList.add(新地板属性(world、floorTexture、overfloorTexture、overfloor2Texture、24、8、1.5f));
floorList.add(新的FloorEntity(world,floorTexture,overfloorTexture,overfloor2Texture,27,5,2));
添加(新的障碍物属性(world、floorTexture、overfloorTexture、overfloor2Texture、25、10、20));
//但是你可能想在右边产生一些东西,就在你的屏幕视图之外。
//这是你的右边
    float timer += Gdx.graphics.getRawDeltaTime();
    //Compare to spawntime
    if (timer >= float spawnTime)
    {
        //Spawn your object
    if (timer >= (float)spawnTime)
    if (timer >= spawnTime)