libgdx 学习笔记(2)

前言

放假之后又要清洁, 现在又要拜年, 学习libgdx 的进度慢了很多

声明

libgdx :https://code.google.com/p/libgdx/

夜明的孤行灯 - android游戏开发框架libgdx的使用(四) --舞台和演员: http://www.cnblogs.com/htynkn/archive/2011/11/15/libgdx_4.html

正文

libgdx 的开发教程中, 其中夜明的孤行灯算是比较早, 但正因为时间较前, 所以会出现部分无法编译的代码.

因为夜明的孤行灯用的0.9.2 版本和现在的0.9.8 版本有部分出入, 这里就以0.9.8 版本为准.


首先是舞台的声明和使用.这里和0.9.2 版本没有什么区别. 依然按照夜明的孤行灯的编写.


然后是Actor 类.这里libgdx 的作者将成员变量(Menber variables)从共有(public)改成私有(private), 并添加了setter/getter 方法. 这是一个很好的现象.但本人表示奇怪, 一开始为甚不干脆这样做呢?

0.9.2 版本

this.height = texture.getHeight();
this.width = texture.getWidth();
//draw(SpriteBatch, float) 方法
batch.draw(texture, this.x, this.y);

0.9.8 版本

this.setHeight(texture.getHeight);
this.setWidth(texture.getWidth);
//draw(SpriteBatch, float) 方法
batch.draw(texture, this.getX(), this.getY());


其他的就不一一举例了.

然后是 Lintener.

在0.9.2 版本中, 是在Actor 类下就有一个 touchUp/Dragged/Down(float, float, int) 方法.

当时我看到这种编写方式, 第一个想法就是, 浪费资源.

现在0.9.8 版本已经放弃了这种方式, 使用Java 的那种委托方式. 我以NarrowButton 类为例.

public NarrowButton() {
	this.addListener(new InputListener(){

		@Override
		public boolean touchDown(InputEvent event, float x, float y,
				int pointer, int button) {
			return super.touchDown(event, x, y, pointer, button);
		}
			
	});
}


然后又回到Actor 类这边, 

之前在0.9.2 版本中,存在构造方法(Constructor)Actor(String) .

button = new NarrowButton("narrow");
但是在0.9.8 版本中, 这个 构造 方法 (Constructor) 不存在了. 又是我的疑问, 这个构造方法 (Constructor) 本来就没什么问题, 为甚删去呢? 现在要这样声明,

button = new NarrowButton();
button.setName("narrow");

感觉更复杂了....


好了, 现在有了setter, 估计还有有一个getter. 在libgdx, 从Stage 上找Actor 的方法是findActor(String)~

又是0.9.2 版本

Actor actor = this.parent.findActor("renwu");

0.9.8 版本是这样的

Actor actor = getParent().findActor("renwu");

因为我的InputListener 是NarrowButton 下的内部类, 如果加上this. 就变了是InputListener.getParent(), 而不是NarrowButton.getParent().

结语

版本的更新, 带来旧版本的不适应不兼容. 

0.9.8 版本相比0.9.2 版本, 有些地方更新得不错, 有些地方却变得复杂了..

是好是坏, 效率说了算~(感觉coder 的地位真低...)





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值