0
我的遊戲中有許多精靈,它們都具有b2world中的物體。並且爲了檢測觸摸接下來我要做的:在檢測到觸摸時在cocos2d中展開testPoint區域
currentPosition = [[CCDirector sharedDirector] convertToGL: currentPosition];
b2Vec2 locationWorld = b2Vec2(currentPosition.x/PTM_RATIO, currentPosition.y/PTM_RATIO);
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
b2Fixture *bf1 = b->GetFixtureList();
if (bf1->TestPoint(locationWorld))
{
CCSprite *tempSprite = (CCSprite *) b->GetUserData();
if (tempSprite.tag==2 )
{
現在,因爲我的精靈的身體太小了,他是移動的,它是非常困難,而其移動到觸摸它,所以我需要改變這個代碼,爲了在這個精靈周圍也檢測一個廣域。 如何將測試點擴展爲+ - 更多50像素?
非常感謝。
謝謝,但他們只寫了4行,看起來很有趣,你能給我一個簡單的例子嗎?我的方式不好? – Curnelious 2011-12-23 18:21:39
查看我的編輯,我從包含的Box2D示例中添加了一個代碼示例。他們是一個很好的學習資源。 – kasrak 2011-12-23 19:37:52
非常感謝我。 – Curnelious 2011-12-24 10:06:56