【问题标题】:Android Studio LibGDX issues [closed]Android Studio LibGDX 问题 [关闭]
【发布时间】:2016-05-20 00:19:27
【问题描述】:

我是编程初学者,我在 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();
    }
}

有人可以帮我解决这个问题吗?我将不胜感激!

【问题讨论】:

    标签: java android android-studio libgdx


    【解决方案1】:

    去掉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 () {
    ...
    

    【讨论】:

      猜你喜欢
      • 2016-06-11
      • 2016-06-10
      • 1970-01-01
      • 2016-06-08
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多