Creating your first app with SimpleGame
创建你的第一个程序SimpleGame
请浏览:http://peigen.info/2010/1/29/Flag-Rush-Tutorial-1/
以后在http://peigen.info/category/JME/更新
impleGame
is a default application type that is included in the jME package. SimpleGame
attempts to take care of everything for you. This makes it easy to get
prototypes up and running. It sets up all the elements such as Camera
, InputHandler
, basic RenderStates
, etc. I'll run through creating a simple application that draws a Sphere
to the screen first, then the next tutorial we will create our own
Application type to give you a better understanding of what is going on
and better control.
第一个小例子SimpleGame是一个默认的程序类型,包括jme的包.SimpleGame帮你注意任何事情.它很容易
的获取原型和运行.它已经设置好了包括Camera,输入帮助类,基本的渲染,等等.我将首先创建一个简单的程序,程序绘画一个球,然后创建一个我们自己
的应用程序让我们更好的明白它是怎么运作的和如何更好的控制它.
First, we will create a new class that extends SimpleGame
. In my case, I'm creating a class Lesson1:
public class Lesson1 extends SimpleGame {}
首先,我们创建一个类并继承SimpleGame
,我创建了一个名字为Lesson1的类:
SimpleGame
contains one abstract method: simpleInitGame. It is in this method that we will create the Sphere
. Add the simpleInitGame method for now, we will come back to the Sphere
later. First, we want to discuss the main method. This is the entry
point for the jME application (just like any Java application). During
creation, you must create your application and tell it to start
executing the game loop. The Main Game Loop
executes the update/render cycle until notified to exit and clean up. To start this loop a call to start is required.
SimpleGame
包括一个抽象方法:simpleInitGame().这是一个用来创建球的方法.先加上simpleInitGame
方法,我们将在后面调用它,首先我们说说main方法.main方法是jME程序的入口点(就像所有的java程序那样).在创建的时候,你必须创建你的
应用程序然后告诉程序用start()方法开始执行程序.main方法执行更新/渲染的循环直到通知其结束和清理为止.启动程序必须调用start()方
法.
To allow the user to specify the window parameters (resolution, fullscreen, etc), we will always display the PropertiesDialog
. Do do this, we set the application behavior to ConfigShowMode.AlwaysShow.
程序允许用户指定窗口参数(分辨率,全屏,等等),我们希望一直显示会话属性那么设置程序的行为为ConfigShowMode.AlwaysShow.
下面是完整程序源码
import com.jme.app.SimpleGame;
public class Lesson1 extends SimpleGame {
/**
* Main method is the entry point for this lesson. It creates a
* SimpleGame and tells the dialog to always appear. It then
* starts the main loop.
* @param args
*/
public static void main(String[] args) {
Lesson1 app = new Lesson1();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
protected void simpleInitGame() {
}
}
The above code should actually compile and run, creating a blank window
(with exception to the framerate and triangle count text).
上面的代码是可以编译运行的,就是创建了一个空白的窗口(有异常输出,帧率,三角形)
Displaying Something
Now, we want to add to the simpleInitGame to display a textured Sphere
. To do so, we need to:
现在,我们想要添加simpleInitGame()显示一个贴图的球型.做这个球,我们需要这样做:
-
读取球
- 读取图片
- 应用图片到球身上
- 添加这个贴图的球到场景
Creation of the Sphere
is as simple as creating a new Sphere
object.
创建这个球是很简单的,就是创建了一个球的对象(Sphere
object.)
Sphere s = new Sphere("Sphere", 30, 30, 25);
s.setLocalTranslation(new Vector3f(0,0,-40));
s.setModelBound(new BoundingBox());
s.updateModelBound();
You define the number of sections on the vertical and the horizontal
(in this case 30 and 30) and its radius (25). That is it. We now have a
sphere
. We can then manipulate the position of the Sphere
.
In this case, we want to move it along the negative Z direction (this
is equivalent to moving it “into” the screen). We then set up the Bounding Volume
of the Sphere
. This allows the Camera's
Frustum Culling
to work. This means, if we turn the camera away from the Sphere
, it will not be drawn (and you will see the statistics drop to 0).
你定义了几个零件它的垂直和水平参数(在这个例子里是30X30)它的半径是(25).现在我们有一个球了.然后我们可以操作求得位置,在这个例子里,我们希望移动它的Z坐标为负值(就相当于把它移进屏幕里).然后我们设置这个球的约束(Bounding Volume
).这允许视角平移(??不确定).这意味着如果我们视角离开球,这个球就不再被绘画了(你将看到统计信息掉到0,.....不明白啥意思)
Next, we will load the Monkey.jpg image and apply it as a texture to the Sphere
. To load an image and obtain a Texture
, we make use of the TextureManager
and its loadTexture method. We will load the image with basic Texture
values.
接下来,我们将读取Monkey.jpg图片再应用其贴到那个球上去.读取图片和获取贴图我们使用TextureManager
管理器的读取贴图的方法.我们将读取图片的基本贴图值
Texture texture = TextureManager.loadTexture(
Lesson1.class.getClassLoader().getResource(
"jmetest/data/images/Monkey.jpg"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
We then create a TextureState
and set this texture to it. To create the TextureState
we use DisplaySystem
as a factory method. SimpleGame
has a reference to the current DisplaySystem
instance: 'display'.
然后我们创建一个TextureState.java设置贴图到其上.创建TextureState我们用DisplaySystem用工厂方法.SimpleGame
参考当前DisplaySystem的实例'display'
TextureState ts = display.getRenderer().createTextureState();
Sets if this render state is enabled during rendering:
ts.setEnabled(true);
We then make use of the setTexture method to place the Texture
of the Monkey.jpg image into the TextureState
. The TextureState
is now ready to be applied to the Sphere, and a call to setRenderState does this. Now that this TextureState
is attached to the Sphere
whenever the Sphere
is rendered, it will use its texture coordinates and apply the image to itself.
然
后我们用setTexture()方法任命贴图Monkey.jpg到TextureState上.那么现在调用setRenderState()方法来
使得TextureState的贴图应用到球上.当球被渲染的时候TextureState已经附到球上了,它僵尸用贴图坐标和图片
ts.setTexture(texture);
s.setRenderState(ts);
Last, we attach the Sphere
to the scene. SimpleGame
provides an object call rootNode that represents the main scene. Attaching the Sphere
to this Node
prepares it for rendering. To attach, simply call:
最后,我们把球附给场景.SimpleGame
提供了一个对象叫rootNode,表示主场景.把球附给这个Node准备渲染,方法为:
rootNode.attachChild(s);
With these few simple calls we have a textured Sphere
rendered to the screen.
用以上的方法我们简单的把一个贴图了的球渲染到屏幕上了.
SimpleGame
,
like its name implies, makes things simple. However, for creating a
full fledged game, we are going to want complete control. Next lesson
will show us how to do this, by creating our own game type.
SimpleGame
,就像名字一样,很简单.然而,做一个羽翼丰满的游戏,我们需要完全的控制,下一讲将讲述如何控制.
分享到:
相关推荐
本资源为Cheat Engine 训练教程,本教程将尝试讲解在游戏中作弊的一些基本知识,并帮助你熟悉 Cheat Engine 的使用方法。通过本应用,可以帮助新人快速入门CE的基本操作方法。如查找数据,修改数据等等
spring的安全框架演示demo,这个是简单的,适合初学者
VASP-tutorial-DielectricsRPA.zip资料vasp密度泛函DFT模拟计算态资料文档下载VASP-tutorial-DielectricsRPA.zip资料vasp密度泛函DFT模拟计算态资料文档下载VASP-tutorial-DielectricsRPA.zip资料vasp密度泛函DFT...
sentinel-tutorial-master.zipsentinel-tutorial-master.zipsentinel-tutorial-master.zipsentinel-tutorial-master.zipsentinel-tutorial-master.zipsentinel-tutorial-master.zip
今天我们要探讨的是PyPI上的一款名为"amuse-tutorial-2021.2.0"的资源,它被封装在"amuse-tutorial-2021.2.0.tar.gz"这个压缩包中。让我们一起深入了解这个Python库的奥秘。 "amuse-tutorial-2021.2.0.tar.gz"是一...
logstash-tutorial-dataset.log
是net-snmp官网上的TUTORIAL-MIB文件,由于官网不太容易登陆,因此贴在这里供大家下载!
【标题】"siobnt-d3-tutorial-源码.rar" 指的是一个压缩文件,其中包含了名为 "siobnt-d3-tutorial" 的源代码教程。D3,全称为 Data-Driven Documents,是由 Mike Bostock 创建的一个强大的JavaScript库,用于数据...
本教程将基于“PyTorch_Tutorial-master.zip”压缩包中的资源,为你提供一个详尽的PyTorch学习路径,让你能够快速掌握这一工具并应用到实际项目中。 1. **PyTorch基础知识** - 动态计算图:与TensorFlow等静态计算...
khcoder-tutorial-en.pdf
在这个" Acegi-security-samples-tutorial-1.0.7.zip "压缩包中,包含了一个详细的教程实例,帮助开发者理解并掌握Acegi Security的使用方法。通过将这些示例代码导入到自己的项目并添加注释,我们可以更深入地学习...
CMake 是一个跨平台的构建系统,用于管理软件项目的构建过程。它通过生成特定平台的构建文件(如 Makefile 或 Visual Studio 工程),简化了多语言和多配置项目的构建。在本教程“cmake_tutorial-master.zip”中,...
SNMP(Simple Network Management Protocol)是一种广泛用于网络设备管理的标准协议,它允许管理员远程监控和配置网络设备。在Linux环境中,SNMP的移植和测试是一个关键步骤,确保系统能够正确地与SNMP代理进行通信...
containers-tutorial-源码.rar
"responsive-hamburger-tutorial-master.zip"是一个包含响应式汉堡菜单教程的压缩包。这个教程主要介绍了如何制作一个响应式的汉堡菜单,即在小屏幕上显示为一个汉堡图标,点击后展开菜单项的导航菜单。教程内容包括...
ns-3项目旨在为研究者和开发者提供一个强大且灵活的工具,用于研究和开发新的网络技术和协议。ns-3-tutorial是官方提供的初学者指南,它详细地介绍了ns-3的安装过程、模块使用方法和示例程序等,旨在帮助初学者快速...
在IT行业中,"热更新"是一种重要的软件维护技术,它允许应用程序在不完全退出或重新启动的情况下进行更新。这种技术对于移动应用尤其重要,因为它提供了更流畅的用户体验,用户无需等待应用完全关闭后再打开新版本。...
这个名为"PyQt5-Chinese-tutorial-master.zip"的压缩包文件,包含了PyQt5的中文教程,对于初学者或寻求进阶学习的开发者来说,是一份非常实用的学习资料。 教程文档以Markdown格式编写,Markdown是一种轻量级的标记...
这个"jainslee-tutorial-04.rar_jain_jainslee example"是一个教程资源,旨在帮助初学者理解并开始使用JAIN SLEE进行开发。 教程《jainslee-tutorial-04.pdf》可能是这个学习路径的核心内容,它涵盖了JAINSLEE的...
策略4:tutorial-checkpoint.ipynb