最近python很热门,大致全部学了一遍,基本会编程了,但是我来看这门语言----这是一门取代matlab称为学院派、科研派的顶级语言,
有点,结合了java与C++的优点,但是只能作为研究。@ python拥有像linux一样的下载lib包的方式,这是非常棒的事情,我在学习C++别人的代码的时候
,总想运行---因为运行别人的代码,是最快捷全部掌握别人的思维的一种方式,可是C++就啦啦了, 我相信一个非常大的工程,运行起来很不容易,
这就是为什么出现了make 、cmake等工具,但是这就是一坨屎,几乎所有的工程代码关联了无数的包,这些可能有不同的格式,不同的版本,编译,
代码巨大,是不行的 @python将复杂的语法简化,它自己制定规则,自己解析,有点像预编译一样,不过更复杂,于是一个庞大的C++项目可能就变成了1000多行
,但是简化语法带了很多意向不到的问题
2:python 像linux一样下载是一件幸福的事情,python不能作为商用语言是有原因的 1在庞大的工程中,它是慢的,这跟他底层有关,
2:个人觉得python的oop方面做得实在不咋地(自己觉得),3:配套的IDE
代码:java版:
一下代码不能运行
public class TestMy implements ApplicationListener {
private boolean paused;
public void create() {
selectedSprite = 0;
cameraHelper = new CameraHelper();
initkey();
createtexture();
batch = new SpriteBatch();
camera = new OrthographicCamera(5.0f, 5.0f);
camera.position.set(0, 0, 0);
camera.update();
}
public void render(){
camera.update();
deltaTime=Gdx.graphics.getDeltaTime();
if(true){
float rotation = testSprites[selectedSprite].getRotation();
// Rotate sprite by 90 degrees per second
rotation += 90 * deltaTime;
// Wrap around at 360 degrees
rotation %= 360;
// Set new rotation value to selected sprite
testSprites[selectedSprite].setRotation(rotation);
if (Gdx.app.getType() != ApplicationType.Desktop) return;
// Selected Sprite Controls
float sprMoveSpeed = 5 * deltaTime;
if (Gdx.input.isKeyPressed(Keys.A)) moveSelectedSprite(-sprMoveSpeed, 0);
if (Gdx.input.isKeyPressed(Keys.D)) moveSelectedSprite(sprMoveSpeed, 0);
if (Gdx.input.isKeyPressed(Keys.W)) moveSelectedSprite(0, sprMoveSpeed);
if (Gdx.input.isKeyPressed(Keys.S)) moveSelectedSprite(0, -sprMoveSpeed);
// Camera Controls (move)
float camMoveSpeed = 5 * deltaTime;
float camMoveSpeedAccelerationFactor = 5;
if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT)) camMoveSpeed *= camMoveSpeedAccelerationFactor;
if (Gdx.input.isKeyPressed(Keys.LEFT)) moveCamera(-camMoveSpeed, 0);
if (Gdx.input.isKeyPressed(Keys.RIGHT)) moveCamera(camMoveSpeed, 0);
if (Gdx.input.isKeyPressed(Keys.UP)) moveCamera(0, camMoveSpeed);
if (Gdx.input.isKeyPressed(Keys.DOWN)) moveCamera(0, -camMoveSpeed);
if (Gdx.input.isKeyPressed(Keys.BACKSPACE)) cameraHelper.setPosition(0, 0);
// Camera Controls (zoom)
float camZoomSpeed = 1 * deltaTime;
float camZoomSpeedAccelerationFactor = 5;
if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT)) camZoomSpeed *= camZoomSpeedAccelerationFactor;
if (Gdx.input.isKeyPressed(Keys.COMMA)) cameraHelper.addZoom(camZoomSpeed);
if (Gdx.input.isKeyPressed(Keys.PERIOD)) cameraHelper.addZoom(-camZoomSpeed);
if (Gdx.input.isKeyPressed(Keys.SLASH)) cameraHelper.setZoom(1);
}
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClearColor(0x64 / 255.0f, 0x95 / 255.0f, 0xed / 255.0f,
0xff / 255.0f);
cameraHelper.applyTo(camera);
batch.setProjectionMatrix(camera.combined);
batch.begin();
for (Sprite sprite :testSprites) {
sprite.draw(batch);
}
batch.end();
}
//这个是假的render2源框架没有,自己方便解释:
public void render2() {
// Do not update game world when paused.
@4------if (!paused) {
float rotation = testSprites[selectedSprite].getRotation();
// Rotate sprite by 90 degrees per second
rotation += 90 * deltaTime;
// Wrap around at 360 degrees
rotation %= 360;
// Set new rotation value to selected sprite
testSprites[selectedSprite].setRotation(rotation);
if (Gdx.app.getType() != ApplicationType.Desktop) return;
// Selected Sprite Controls
float sprMoveSpeed = 5 * deltaTime;
if (Gdx.input.isKeyPressed(Keys.A)) moveSelectedSprite(-sprMoveSpeed, 0);
if (Gdx.input.isKeyPressed(Keys.D)) moveSelectedSprite(sprMoveSpeed, 0);
if (Gdx.input.isKeyPressed(Keys.W)) moveSelectedSprite(0, sprMoveSpeed);
if (Gdx.input.isKeyPressed(Keys.S)) moveSelectedSprite(0, -sprMoveSpeed);
// Camera Controls (move)
float camMoveSpeed = 5 * deltaTime;
float camMoveSpeedAccelerationFactor = 5;
if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT)) camMoveSpeed *= camMoveSpeedAccelerationFactor;
if (Gdx.input.isKeyPressed(Keys.LEFT)) moveCamera(-camMoveSpeed, 0);
if (Gdx.input.isKeyPressed(Keys.RIGHT)) moveCamera(camMoveSpeed, 0);
if (Gdx.input.isKeyPressed(Keys.UP)) moveCamera(0, camMoveSpeed);
if (Gdx.input.isKeyPressed(Keys.DOWN)) moveCamera(0, -camMoveSpeed);
if (Gdx.input.isKeyPressed(Keys.BACKSPACE)) cameraHelper.setPosition(0, 0);
// Camera Controls (zoom)
float camZoomSpeed = 1 * deltaTime;
float camZoomSpeedAccelerationFactor = 5;
if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT)) camZoomSpeed *= camZoomSpeedAccelerationFactor;
if (Gdx.input.isKeyPressed(Keys.COMMA)) cameraHelper.addZoom(camZoomSpeed);
if (Gdx.input.isKeyPressed(Keys.PERIOD)) cameraHelper.addZoom(-camZoomSpeed);
if (Gdx.input.isKeyPressed(Keys.SLASH)) cameraHelper.setZoom(1);
}
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClearColor(0x64 / 255.0f, 0x95 / 255.0f, 0xed / 255.0f,
0xff / 255.0f);
cameraHelper.applyTo(camera);
batch.setProjectionMatrix(camera.combined);
batch.begin();
for (Sprite sprite :testSprites) {
sprite.draw(batch);
}
batch.end();
}
@3-------public void pause() {
paused = true;
}
public void resume() {
paused = false;
}
public static void main(String[] args) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.title = "bbbb";
LwjglApplication app = new LwjglApplication(new TestMy(), config);
}
}
如果想要知道,绝对要把这个框架研究透,不然你绝对写不出来的,
核心代码:LwjglApplication.class/mainLoop()中
在
boolean wasActive = true;while (this.running) {
Display.processMessages();
if (Display.isCloseRequested()) exit();
boolean isActive = Display.isActive();
if ((wasActive) && (!isActive)) {
wasActive = false;
synchronized (lifecycleListeners) {
for (LifecycleListener listener : lifecycleListeners)
listener.pause();
}
this.listener.pause();
}
if ((!wasActive) && (isActive)) {
wasActive = true;
synchronized (lifecycleListeners) {
for (LifecycleListener listener : lifecycleListeners)
listener.resume();
}
this.listener.resume();
}
在刚开始运行的时候,我们创建了两个线程,一个主线程main,另一个就是mainLoopThread线程了,这段代码中mainLoopThread就是一个while线程(总是在运行)中
isActive 就是取windows的状态是否是激活,wasActive,
@1(wasActive) && (!isActive) 这段话, 这个就是我们的最前面的是游戏client段(!isActive)就是false,wasActive就是true,于是不走,
下面的@2 if ((!wasActive) && (isActive))也不走,当我们移开client的时候,isActive 就是false,于是@1我们就是进入,我们同步调用listener.pause(),这个调用的就是
@3于是 render2的@4就不运行了,@4部分就是处理按键运动的,这个不运动了就是暂停,画面就是静止了,
@2(!wasActive) 为true于是,当我们将client置顶层的时候,点击时,isActive就为true于是,我们this.listener.resume(); 我们的render2又全部能运行了,
这个有点坑,
libgdx后端逻辑帮你搞定了,如果不看代码你不知道,如果看了代码,做了,你就觉得libgdx非常牛逼的