Collision Filters "Helper Chart"
碰撞過濾器“幫手圖“


Hello all,大家好


I'm posting the following explanation about Collision Filters as a help to the community in general, as a result of my own experiments. Some users, especially recent converts, have not yet used collision filters but it's an essential aspect to almost any game design. I created the attached "Collision Helper Chart" which I use for my own game designs... hopefully it can assist others too! The blank document can be downloaded from my website (link at the end of this post).
我下面的解釋張貼關於碰撞過濾器的幫助,對社會一般,因此我自己的實驗。有些用戶,特別是最近的轉換,還沒有使用過濾器的碰撞,但它是一個重要的方面幾乎所有的遊戲設計。我創建了附加“碰撞助手圖“,我用我自己的遊戲設計...希望它能夠幫助別人呢!空白文件可從我的網站(鏈接在結束這篇文章)。


-----


So, what are Collision Filters? Simply put, they're a method to determine what objects combine with other objects, or perhaps more importantly, what objects do not collide with others in a game. The official documentation explains Corona's method of accomplishing this, which varies from other SDKs, but I created a chart to assist in the issue.
那麼,什麼是碰撞過濾器?簡而言之,他們是一個方法來確定哪些對象與其他對象相結合,或者更重要的是,哪些對象不與他人發生碰撞在遊戲中。官方文檔解釋Corona的方法實現這一點,從其他SDK而異,但我創建了一個圖表,以協助問題。


Here's a chart and list of steps following the classic "Asteroids" game example...
這裡有一個圖表,列出以下步驟經典的“小行星“的遊戲例子...






STEPS:

1.Observe the "bits" (numbers) in the very top row. 1 to 512, in binary numbers. You can go as high as "32768" (16 places) but I stopped the chart at 512 which should be enough for most people. These "bits" are how Corona determines collision filters.
遵守“位元“(數字)排在最高層。 1到512,在二進制數字。你可以去高達“32768“(16處),但我停在512的圖表應足以讓大多數人。這些“位元“是如何確定Corona碰撞過濾器。

2.Observe the first row. It has two sub-rows: "catg." and "cl.w/". These mean "category" and "collides with" respectively.
遵守第一行。它有兩個子行:“catg。“和“cl.w/“。這意味著"category"和"collides with"分別。

3.For each object type in your game (i.e. "asteroid", pick one bit number. Place a circled X in that column. This bit number should be unique and not repeated for other objects under most circumstances! (There are probably advanced situations where you might duplicate category bits or even assign more than one to an object, but don't worry about it now)
對於每個對象類型在你的遊戲(即“小行星“,選擇一個位元的數字。放置一個圈X的在該列。該位元號碼應該是唯一的,而不是重複其他對象在大多數情況下!(有可能是先進的情況下,您可能會重複類別位元,甚至超過一個指定的對象,但不用擔心了)

4.Next, ask yourself: "can this object collide with others of its type?" If yes, then place an X directly below in the "collides with" row. In the example, notice that asteroids can collide with other asteroids.
4.接下來,問自己:“這個對象可以與他人發生衝突的類型?“如果是的話,然後直接在 "collides with"那行 放一個X 。在這個例子中,可以發現小行星碰撞與其他小行星。

5.Move down the rows of other objects in your game. For every object that "asteroids" can collide with, place an X in the "collides with" row for that object. Asteroids can collide with player_ship and alien_ship, so both of those get an X in their respective row/column. If it's not obvious already, keep the columns ordered: Asteroids have bit "2" as their category, so stay within that column for anything asteroids should collide with (I colored the chart entries to make it clearer).
5.向下行的其他對象在你的遊戲。對於每一個對象,“小行星“可以碰撞,放置一個 X在“collides with“行該對象。小行星可能撞到player_ship和alien_ship,所以這些都得到了X在各自的行/列。如果它已經不很明顯,繼續列下令:小行星有位元“2“,其類別,所以留在該列中任何小行星會撞上(我彩色圖表,使之更清晰的條目)。

6.Move to the next game object and repeat. IMPORTANT! You must work back UP the chart, not just down! If two objects are intended to collide, both must be marked properly or the collision will not function! 
6.移動到下一個遊戲對象和重複。重要!您必須備份圖表,而不僅僅是下來!如果兩個對象是為了碰撞,都必須標明正確或碰撞將無法正常工作!

So, take the item pair of asteroid and player_ship, which should always collide: "asteroid: category" is marked in "player_ship: collide with" AND "player_ship: category" is marked in "asteroid: collide with". If you fail to mark both corresponding factors, the collision will not happen!
因此,採取項目對小行星和player_ship,這應該永遠碰撞:“小行星:category“標記在“player_ship:collide with“及”player_ship:category“標記在“小行星:collide with“。如果你沒有標出對應的因素,不會發生碰撞!

7.When you've done all of your objects, simply add the bits across every row to determine sums.
7.當你已經做了所有你的對象,只需添加位元在每行,以確定的數額。

8.For each collision filter, you need these sums as follows, near the top of your main.lua file.
8.對於每一個碰撞過濾器,你需要這些款項如下,頂部附近你main.lua文件。
---------------
local asteroidCollisionFilter = { categoryBits = 2, maskBits = 7 }
local playerCollisionFilter = { categoryBits = 1, maskBits = 6 }
local alienCollisionFilter = { categoryBits = 4, maskBits = 7 }
------------------------
categoryBits is the sum from the "category" row for that object. 
categoryBits是總結從“類別“行該對象。

maskBits is the sum from the "cl.w/" row for that object.
maskBits是總結從“cl.w/“行該對象。


9.Later, in your physics body declarations, specify the collision filter. Obviously, define the proper filter for every object in your game, as declared near the top of your game code.
9.後來,在你的物理身體聲明,指定過濾器的碰撞。顯然,確定適當的過濾器,每一個對象在你的遊戲,這一點已接近頂部的你的遊戲的代碼。
--------------
local asteroid = display.newImageRect( [displayGroup], "asteroid.png", 32, 32 )
physics.addBody( asteroid, { density=2.9, friction=0.5, bounce=0.3, radius=16, filter=asteroidCollisionFilter } )
-------------
That's it! Remember the basic rules of collisions and body types. "Dynamic" bodies react physically with other "dynamic" or "static" bodies, but not with "kinematic" bodies. While confusing at first, it will soon make complete sense.
就是這樣!記住的基本規則和身體碰撞類型。 “動態“身體反應,身體上的其他“動態“或“靜態“的機構,但不符合“運動“組織。雖然一開始混亂,它很快就會作出完整意義上的。


Anyway, hopefully this helps some new Corona users, or even gives veterans a more visual way to calculate collision filters. If anybody at Ansca or in the community sees any errors in my description, please let me know! I'm not an Ansca staff member or Corona expert; all of this is just a result of my own personal testing and experimentation. :)
無論如何,希望這有助於一些新的Corona用戶,甚至給退伍軍人更直觀的方式來計算碰撞過濾器。如果有人在Ansca還是在社區中看到任何錯誤,我的描述,請讓我知道!我不是一個 Ansca工作人員或Corona的專家,所有這一切,僅僅是一個結果我個人的測試和試驗。 :)


And here's a link to the blank "chart" document in PDF format. You can download it from my website and print it for your own use: Collision Filter Helper Chart (PDF)
下面是一個鏈接到空白的“圖表“文件的PDF格式。你可以從我的網站下載並打印供自己使用:碰撞過濾助手圖(PDF)

arrow
arrow
    全站熱搜

    createps 發表在 痞客邦 留言(0) 人氣()