【发布时间】:2012-02-13 15:09:25
【问题描述】:
我是编程新手,我尝试过 ray wenderlich 教程,但我仍然感到困惑。
我有一个名为 rock 的精灵和一个名为 player 的精灵,我试图检测它们之间的碰撞。但我非常困惑。需要一些帮助。
-(void)addRock {
CCSprite *rock = [CCSprite spriteWithFile:@"rock.png"
rect:CGRectMake(0, 0, 27, 40)];
// Determine where to spawn the target along the X axis
CGSize winSize = [[CCDirector sharedDirector] winSize];
int minX = rock.contentSize.width/2;
int maxX = winSize.width - rock.contentSize.width/2;
int rangeX = maxX - minX;
int actualX = (arc4random() % rangeX) + minX;
// Create the target slightly off-screen along the right edge,
// and along a random position along the X axis as calculated above
rock.position = ccp(actualX, 500);
[self addChild:rock];
// Determine speed of the sprite
int actualDuration = 5;//speed of sprite
}
- (id)init {
if ((self=[super init])) {
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCSprite *player = [CCSprite spriteWithFile:@"Player.png"
rect:CGRectMake(0, 0, 27, 40)];
player.position = ccp(winSize.width/2, winSize.height/4+15);
[self addChild:player];
[self schedule:@selector(gameLogicRock:) interval:0.2];
它们是两个精灵,它们生成和定位正确,我只需要检测碰撞
【问题讨论】:
-
请更正您的代码。它杂乱无章,难以阅读。
-
好的,只是整理了一下......对不起
标签: cocos2d-iphone box2d-iphone