0
即时通讯新编程,我已经尝试了射线wenderlich教程,但即时通讯仍然困惑。box2d碰撞检测,代码
我有一个叫做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];
他们是两个精灵,它们产卵,正确的位置,我只需要检测碰撞
请更正您的代码。它杂乱无章,难以理解。 – 2012-02-13 15:12:51
好的,只是整齐的...对不起 – sahil 2012-02-13 15:56:40