我已經編寫了一個代碼來顯示使用CCLog時精靈的精確位置,當一個鼠標聯合移動它被釋放時。下面是Sprite.mm類和ccTouchesEnded方法(它在HelloWorldLayer.mm類中)。 CCLog不顯示消息。CCLOG不顯示
Sprite.mm:
-(id)addSprite:(CCLayer *)parentLayer
inWorld:(b2World *)world
{
PhysicsSprite *aSprite = [PhysicsSprite spriteWithFile:@"spriteIm.png"];
aSprite.tag = 1;
[parentLayer addChild:aSprite];
b2BodyDef spriteBodyDef;
spriteBodyDef.userData = aSprite;
spriteBodyDef.type = b2_dynamicBody;
CGSize s = [CCDirector sharedDirector].winSize;
spriteBodyDef.position = [Convert toMeters:ccp(s.width * 0.25,s.height-400)];
b2FixtureDef fixtureDef;
fixtureDef.density = 0.01;
b2CircleShape circleShape;
circleShape.m_radius = aSprite.contentSize.width/2/PTM_RATIO;
fixtureDef.shape = &circleShape;
spriteBody = world->CreateBody(&spriteBodyDef);
spriteFixture = spriteBody->CreateFixture(&fixtureDef);
[aSprite setPhysicsBody:spriteBody];
return aSprite;
}
ccTouchesEnded:
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (mouseJoint)
{
for(b2Body *b = world->GetBodyList(); b; b=b->GetNext()) {
if (b->GetUserData() != NULL) {
CCSprite *mySprite = (CCSprite *)b->GetUserData();
if (mySprite.tag == 1) {
CGPoint spritePosition = mySprite.position;
CCLOG(@"the sprite position is x:%0.2f, y:%0.2f", spritePosition.x, spritePosition.y);
}
}
}
world->DestroyJoint(mouseJoint);
mouseJoint = NULL;
}
}
我有一種感覺,這個問題是我在訪問標籤,真的不知道的方式。請幫忙。
設置通過線代碼行一個斷點和步驟:http://www.learn-cocos2d.com/2011/10/xcode-4-debugging-crashcourse/ – LearnCocos2D 2012-08-09 21:01:55