2016-02-09 126 views
-1

我是一名編程初學者,我在Youtube上找到了關於如何使用Android Studio和LibGDX編寫簡單遊戲的視頻教程。直到第34部分('https://www.youtube.com/watch?v=2R_e9wceHZA'),教程都很不錯。我創建了FloorEntity和SpikeEntity('在我的項目中,它指的是StingEntity')。當我運行它時,Android Studio抱怨一系列錯誤。這些錯誤有以下幾種:Android Studio LibGDX問題

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

'(); {' - >'(){' – njzk2

回答

0

處置後刪除分號(;)

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

且正在嘗試做定義一個函數(多次)的內部函數。大括號設置不正確。確定在定義一個新功能之前關閉一個功能。

實施例:

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

} //<- inserted 

@Override 
public void hide() { 
...