多语言展示
当前在线:133今日阅读:176今日分享:34

libgdx:[41]游戏世界组合

移除一些旧代码并实现游戏界面
工具/原料

libgdx

Assembling the game world 组装游戏世界
1

我们将要移除我们用来绘制所有的检测用的sprites的代码。另外我们会添加三个常量来标识初始生命值和GUI相机的视窗尺寸。Change the code of Constantsclass as follows:对Constant类的代码做出如下改变:代码部分请参照图书

2

Now, remove these two lines of code in WorldController:移除WorldController的这两行代码:***public Sprite[] testSprites;***|***public int selectedSprite;***|Additionally, removethe following methods in WorldController:另外移除WorldController中的如下方法:****•  initTestObjects()****|****•  updateTestObjects()****|****•  moveSelectedSprite()****|

3

移除WorldController的handleDebugInput()方法中的如下代码:代码... ...

4

Next, remove the code below the two comments 'Select next sprite' and 'Toggle camera follow' in the keyUp()method of WorldControllerso that the resulting method looks like this:移除WorldController中keyUp()方法的'Select next sprite'和'Toggle  camera follow'两个注释的 内容以便代码如下所示:

5

把下面的两个实现代码添加到WorldControllerimport com.packtpub.libgdx.canyonbunny.game.objects.Rock;import com.packtpub.libgdx.canyonbunny.util.Constants;下一步添加下面代码到WorldController:public Level level;public int lives;public int score;private void initLevel () {score = 0;level = new Level(Constants.LEVEL_01);}

6

Change the code in the init()method of WorldController as follows:如下面代码更改WorldController的init方法:。。。 。。。

8

我们现在移除了所有的旧代码并添加了level 加载到controller中。还有两个变量score 和lives 来计算玩家的生命值和分数。我们还必须对 CameraHelper类做一些小的改变,把对sprite 的使用切换到AbstractGameObject。

9

Remove the following import line in CameraHelper:移除CameraHelper中的import代码:***import com.badlogic.gdx.graphics.g2d.Sprite;下一步添加代码到CameraHelper::import com.packtpub.libgdx.canyonbunny.game.objects.AbstractGameObject;现在对CameraHelperas 做出如下改变:代码。。。 。。。 。。。

10

Next, add the following code in WorldRenderer:向WorldRenderer中添加代码如下:移除WorldRenderer中的renderTestObjects() 方法最后用rederWorld()方法替换已经删除的renderTestObjects()方法。public void render () {renderWorld(batch);}现在世界绘制器将会调用renderWorld()方法,它会调用Level 的render()方法,绘制所有的加载的level的游戏对象。

推荐信息