(libgdx学习)Continuous & non continuous rendering

官方文档部分解释

1)By default in libgdx, the rendering thread calls the render() method of your ApplicationListener class continuously, with a frequency that depends on your hardware (30-50-80 times per second).

If you have many still frames in your game (think about a card game) you can save precious battery power by disabling the continuous rendering, and calling it only when you really need it.

All you need is put the following lines in your ApplicationListener's create() method

Gdx.graphics.setContinuousRendering(false);
Gdx.graphics.requestRendering();

The first line tells the game to stop calling the render() method automatically. The second line triggers the render() method once. You have to use the second line wherever you want the render() method to be called.

在libgdx中,默认是由render thread不断地调用render()方法。如果你不想render()方法被自动的调用,这时候你可以Gdx.graphics.setContinuousRendering(false);//不再自动调用render()方法

在不再自动调用之后,你应该加一句

Gdx.graphics.requestRendering();//手动调用render()方法

2)

If continuous rendering is set to false, the render() method will be called only when the following things happen.

  • An input event is triggered //input event发生
  • Gdx.graphics.requestRendering() is called //requestRendering()方法被调用
  • Gdx.app.postRunnable() is called //postRunnable()方法被调用
当不再自动调用render()方法后,render()方法在一下情况自动调用。

二、应用举例

package com.example.groupactiontest;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Input.Peripheral;
import com.badlogic.gdx.graphics.GL10;

public class MyGame implements ApplicationListener {

	
	
	int counter = 1;
	@Override
	public void create() {
		Gdx.graphics.setContinuousRendering(false);//不再自动调用render()方法
		
		Gdx.graphics.requestRendering();//手动调用render()方法
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void render() {
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		
		System.out.println("------------->" + counter++);
		
	}

	@Override
	public void resize(int arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

}


四、源码下载

http://download.youkuaiyun.com/detail/caihongshijie6/7052325




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值