• About
    • Resume
A Game Developer also plays some guitar

在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

About Benny Chen

A game developer, a music lover, and a partisan fan of F.C. Barcelona

View all posts by Benny Chen →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

Post Navigation

← Previous Post
Next Post →

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