Android Studio LibGDX问题

时间:2016-02-09 20:43:25

标签: java android android-studio libgdx

我是编程的初学者,我在Youtube上找到了关于如何使用Android Studio和LibGDX编写简单游戏的视频教程。在第34部分('https://www.youtube.com/watch?v=2R_e9wceHZA')之前,教程非常顺利。我创建了FloorEntity和SpikeEntity('在我的项目中它指的是StingEntity')当我运行它时,Android Studio会抱怨一系列错误。错误如下:

Error:(62, 24) Gradle: error: ';' expected
Error:(77, 22) Gradle: error: ';' expected
Error:(77, 34) Gradle: error: ';' expected
Error:(87, 23) Gradle: error: ';' expected
Error:(91, 1) Gradle: error: reached end of file while parsing

GameScreen.java中的代码如下:

package com.mygame;

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.World;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.mygame.desktop.BaseScreen;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.mygame.entities.FloorEntity;
import com.mygame.entities.PlayerEntity;
import com.mygame.entities.StingEntity;
import com.mygame.scene2d.ActorSting;

import java.util.ArrayList;
import java.util.List;


public class GameScreen extends BaseScreen {

    private Stage stage;

    private World world;

    private PlayerEntity player;

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

    private List<StingEntity> stingList = new ArrayList<StingEntity>();

    public GameScreen(MainGame game) {
        super(game);
        stage = new Stage(new FitViewport(640, 480));

        world = new World (new Vector2(0,-10), true);



    }

    @Override
    public void show() {
        Texture playerTexture = game.getManager().get("blockman.png");
        Texture floorTexture = game.getManager().get("floor.png");
        Texture overfloorTexture = game.getManager().get("overfloor.png");
        Texture stingTexture = game.getManager().get("sting.png");

        floorList.add(new FloorEntity(world, floorTexture, overfloorTexture, 0, 1000, 1));
        stingList.add(new StingEntity(world, stingTexture, 6, 1));


        player = new PlayerEntity(world, playerTexture, new Vector2(1, 2));
        stage.addActor(player);
        for (FloorEntity floor : floorList) {
            stage.addActor(floor);
        }
        for (StingEntity sting : stingList) {
            stage.addActor(sting);
        }

        @Override
        public void hide () {
            player.detach();
            player.remove();
            for (FloorEntity floor : floorList) {
                floor.detach();
                floor.remove();
            }
            for (StingEntity sting : stingList) {
                stage.addActor(sting);
                sting.detach();
                sting.remove();
            }
    }

    @Override
    public void render(float delta) {
        super.render(delta);
        Gdx.gl.glClearColor(0.4f, 0.5f, 0.8f, 1f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stage.act();
        world.step(delta, 6, 2);
        stage.draw();
    }

    @Override
    public void dispose();{
        stage.dispose();
        world.dispose();
    }
}

有人可以帮帮我吗?我将不胜感激!

1 个答案:

答案 0 :(得分:0)

在dispose()

后删除分号
@Override
public void dispose();{
    stage.dispose();
    world.dispose();
}

您正在尝试在函数内部定义函数(多次)。您的花括号设置不正确。确保在定义新功能之前关闭该功能。

示例:

@Override
public void show() {
...
       for (StingEntity sting : stingList) {
            stage.addActor(sting);
        }

} //<- inserted

@Override
public void hide () {
...