• About
    • Resume
A Game Developer also plays some guitar

Tag Archives: 2d

基于Moai的Pacman

August 29, 2011 10:49 pm / 4 Comments / Benny Chen

最近一两个星期,在业余时间利用Moai引擎重写了当年曾经用DirectX实现过的Pacman游戏。基于Lua的代码基本上是重写,只是保留使用了之前的2D资源。重写的目的一是通过这个来熟悉Moai引擎,二是希望用一个比较好的OO结构来重新实现Pacman,三则纯粹因为好玩。

把所有的代码,资源和文档都已经上传到了github,github真的是个好东东。

https://github.com/bennychen/Moai-based-Pacman

介绍:

This is a prototype game based on the Moai game platform – http://getmoai.com. With various APIs for drawing and handling different 2D elements that Moai has supported, it clones a 2D Pacman game.

I programmed the game for several objectives. Firstly, because I am just new to Moai, I try to familiarize myself with Moai’s various APIs and game development based on it. I did encounter some issues when programming the game. Some were because I am a newbie for Moai, and some were testified later that were from Moai engine itself. Although the process was time-consuming, but to my pleasure, this is somewhat a contribution to the open source Moai engine itself. I feel a great joy to be part of it. Secondly, the whole game is based on OO. So I tried to program the whole game with a decent OO structure. Most importantly, some of the Lua classes or files, hopefully, can be reused in my other future potential games.

All in all, I programmed Moai-based Pacman for fun and share my code, related game assets and documents here. If there can be any help for you who are interested in Moai and OO game programming, that would be my best honer.

Posted in: Game Programming, Lua, My Projects / Tagged: 2d, github, Moai, oo, pacman

在Moai Forum的问题帖

August 21, 2011 10:26 am / Leave a Comment / Benny Chen

(关于Moai,见我的上一篇文章。)

下面贴出在Moai Forum上我最近的两个问题帖。回答者都是Patrick,他是Moai引擎的领导者,同时也是’Zipline Games’的CTO。他似乎是个不错的人,在我每次贴出问题后,总是在最快的时间内解答。

1. Does MOAILayer2D only support 512 props maximumly?

http://getmoai.com/forums/moai-sdk-developer-support/does-moailayer2d-only-support-512-props-maximumly/

Me:

I was trying to put lots of props onto a layer with function MOAILayer2D:insertProp, but found that if I inserted more than 512 props, all the props will fail to render on the layer. Is 512 the threshold for a layer’s prop count? Why is it a restriction? 512 doesn’t suffice my need. If there did exist a restriction, Moai even didn’t tell me any info or warning about the number 512, it took me lots of time to detect the problem and the number… 🙁

Patrick:

Sorry you had to spend your time on that. I agree that we could emit better warnings for situations like that.

The 512 restriction is arbitrary. It’s the size of the buffer created on the stack to sort the prims. I can fix it for you in the next release – will grow the buffer dynamically instead. When I have time to add an option to disable sorting by MOAILayer2D, the buffer won’t be needed at all.

If you need a fix immediately and are building from source, you can go into MOAILayer2D and just change it to something else.

(512 props is a lot! Is this for a mobile game? Mind if I ask what you’re displaying? Depending on what it is, may be other ways I can help.)

Patrick:

OK. I removed MAX_RENDERABLES and now use a flexible size buffer to gather and sort the props returned from the partition. That will be in the upcoming release. Try it out and let me know.

If you run into stuff like this in the future (any kind of odd or mysterious behavior) please let me know and I’ll hop right on it. Would much rather deal with a few false positives than have you waste your time!

Me:

Thanks so much for your reply and help, Patrick.

I’m just new to Moai. I was generating and displaying a map (31×28 grids) with each grid empty or filled with a type of sprite (like a the Pacman game, each grid could be filled with a Wall or a Bean or …). So this is why I used so MANY props. Do you have some other way or suggestions for generating such kind of game maps, so that not that many props will be used?

As you’ve fixed this issue, so I’m looking forward to the next release. Thanks a bunch!

Patrick:

Absolutely. Check out MOAITileDeck2D and MOAIGrid. Any of the deck types can be used in conjunction with a grid, but MOAITileDeck2D is ideally suited. The grid draws with one transform (from the prop it’s attached to) and also gets viewport culled on a per tile basis. It’s ideally suited to tiled backgrounds. You will get way better performance and can also update the grid values at runtime or animate them using a MOAIDeckRemapper. Check out tilemap-animated for a sample. In the games we are working on in-house we have multiple layers of tilemap parallax drawing hundreds and hundred of tiles at really good frame rates. If you need to animate a tile flipping or rotating (like what happens to a block in a Mario game when Mario hits it with his head), just hide the original tile in the grid and replace it with a prop – you can use the same tile deck as the source for the prop.

Also, can’t say enough good things about Tiled (mapeditor.org). The latest version supports flip flags and can output its data as Lua tables you can then load in to Moai (with a little bit of work).

Always a pleasure to help out, so let me know if you have more questions as you go.

Me:

Oh, how stupid I was that I didn’t find these classes, I will try these MOAI classes later. THANK YOU!

2. Questions about MOAIAction:stop

http://getmoai.com/forums/moai-sdk-developer-support/questions-about-moaiactionstop/

Me:

I have some questions regarding the usage of MOAIThread and MOAIAction

Firstly check out the code snippets below.

MOAISim.openWindow ( "test", 320, 480 )</span>
viewport = MOAIViewport.new ()
viewport:setSize ( 320, 480 )
viewport:setScale ( 320, 480 )

layer = MOAILayer2D.new ()
layer:setViewport ( viewport )
MOAISim.pushRenderPass ( layer )

gfxQuad = MOAIGfxQuad2D.new ()
gfxQuad:setTexture ( "cathead.png" )
gfxQuad:setRect ( -64, -64, 64, 64 )

prop = MOAIProp2D.new ()
prop:setDeck ( gfxQuad )
layer:insertProp ( prop )

function moveThreadMain()
	movingAction = prop:moveLoc( 1000, 0, 100, MOAIEaseType.LINEAR )
	local x
	local y
	while ( movingAction:isBusy() )
	do
		x, y = prop:getLoc()
		print( "current x - " .. x )
		coroutine.yield()
	end
end

isCrossBound = false
function checkThreadMain()
	while ( true )
	do
		local x
		local y
		x, y = prop:getLoc()
		if ( isCrossBound == false )
		then
			if ( x > 20 )
			then
				isCrossBound = true
				movingAction:stop()
				print( "x after stop current frame - " .. x )
			end
		else
			print( "x after stop next frame - " .. x )
			break
		end
		coroutine.yield()
	end
end

moveThread = MOAIThread.new()
checkThread = MOAIThread.new()
moveThread:run( moveThreadMain )
checkThread:run( checkThreadMain )

I start and run 2 threads. The ‘moveThread’ uses MOAIAction to move the prop continuously and print its location each frame, while another ‘checkThread’ checks if the prop crosses some bound and if yes stops the moving animation with function MOAIAction:stop

But the result of MOAIAction:stop differs based on the launching sequence of those above 2 threads.

If I run ‘checkThread’ before ‘moveThread’, here is the result. MOAIAction::stop successfully stopped moving prop.

x after stop current frame – 20.099973678589
x after stop next frame – 20.099973678589

But if I run ‘movingThread’ before ‘checkThread’, I will get the following result, seems that animation will continue running for another frame

x after stop current frame – 20.099973678589
x after stop next frame – 20.199974060059

This really confuses me. Can anyone do me a favor to explain at which condition MOAIAction will run an additional frame after stopped, and when not? Is there a way to ensure that MOAIAction:stop will run no more frame no matter the running sequence of MOAIThread?

Patrick:

Just ran your code. It’s a legitimate bug in the way the MOAIAction update loop works. I’ve fixed it and checked it in to ‘master’ on moai-dev. We should have the next binary release out early next week.
Thanks for finding this!

Posted in: Game Programming / Tagged: 2d, forum, game engine, Moai, MOAIAction, MOAILayer2D, MOAIThread

Moai

August 21, 2011 10:24 am / Leave a Comment / Benny Chen

最近通过澳洲朋友Andrew的介绍,开始使用了一款正在开发中的开源游戏引擎Moai – the mobile platform for pro game developers.

Moai是一款由’Zipline Games’公司开发的2D游戏引擎,我写这篇文章时的版本是0.5 Beta。它最大的特点就是集成了Lua脚本语言,它提供了一系列class-based的Lua API。开发者一般只需要通过写Lua脚本,即可实现一款游戏。而引擎本身解决了跨平台的问题,开发完的游戏可以顺利的发布到iOS和Android平台。而引擎本身提供的功能上,也基本上覆盖了需要开发一款2D游戏所有的元素,设备和输入,2D Sprite,动画,字体,粒子系统,物理,声音等。Moai的另外一个重要特色是提供了一个它称之为Moai Cloud的云服务,对于这个我还没有深研究,不过据称它可以让需要后端server的游戏变得简单,用户同样只需要用Lua来编写server的逻辑代码,而至于像scale-up这样的问题完全可以交给Moai引擎来处理。

然而开源引擎,尤其是处于Beta测试中的开源引擎,想用于开发正式的游戏确实有些不可靠。我最近在把之前写过的一个Pacman 2D移植到Moai上,但是遇到了很多的问题,并且一些问题最终通过层层纠结后证实是引擎本身的问题。虽然过程坎坷,但因为参与开源引擎项目,并有了自己的contribution,这本身着实是一件令人欣慰而振奋的事情。

但是希望Moai的开发者们work harder,让Moai尽快变得更好 😀

注册并获取Moai:http://dashboard.moaicloud.com/

Moai入门文章:
第一部分:http://getmoai.com/2011/04/moai-basics-part-1/
第二部分: http://getmoai.com/2011/04/moai-basics-part-2-2/

Moai API Documentation:http://getmoai.com/docs/

Posted in: Game Programming / Tagged: 2d, beta, cloud, game engine, lua, Moai, mobile, zipline games, 开源

LinkedIn

Milan Petrovic

Categories

  • In My Life (25)
    • A Day in the Life (8)
    • English Learning (2)
    • Learn a Word (7)
    • Something In The Way (8)
  • Music Heaven (8)
    • Guitar (1)
    • In Concert (1)
    • Lyrics (3)
  • OK Computer (54)
    • 3D (3)
    • C++ (10)
    • Computer Graphics (15)
    • Game Programming (23)
    • iOS (6)
    • Linux (1)
    • Lua (9)
    • My Projects (3)
    • Some Experiences (9)
    • Talking in Code (2)
    • Unity (2)
  • Quotations (2)
  • Uncategorized (1)
  • Visca Barça (24)
    • FCB BJ (5)

Recent Posts

  • [译]优化你的手机游戏(没有延迟的,才是健康的)- 一篇给游戏美术设计师读的文章
  • 新浪微博API for MOAI
  • 稍后继续
  • Unity Developer ++
  • Another Thread @ Moai Forum
  • 1st Day of Golden Week
  • 为SyntaxHighlighter添加新语言
  • 基于Lua的State Pattern
  • Class Diagram of Pacman
  • 基于Moai的Pacman

Recent Comments

  • 约修亚_RK on 为SyntaxHighlighter添加新语言
  • 爱装的小男孩 on 小心DLL链接静态库时的内存错误
  • happyfire on Game Loop的几种实现方式
  • William on 新浪微博API for MOAI
  • Benny Chen on 新浪微博API for MOAI
  • your man on 新浪微博API for MOAI
  • 你家男人 on 稍后继续
  • 逍遥 on 关于对std::vector的遍历
  • papa on Unity Developer ++
  • T客网 ︱ Techpot » Blog Archive » iOS开发与OpenGL ES相关问题整理(1) on iOS开发与OpenGL ES相关问题整理(1)

Tags

2d 3D 3dsmax 3ds max air Apply architecture Asia tour barca Beijing bilbao binary search blocked bob boost bruce springsteen C++ capo CGContextDrawImage Champions League Change DLL DX10 eval exporter flash framework frustum culling game game engine iniesta ios linux lua Moai opengles pacman plug-in plugin 北京 导出插件 崩溃 巴萨 游戏引擎 踢球
© Copyright 2026 - A Game Developer
Infinity Theme by DesignCoral / WordPress