나는 내 화면에 다양한 스프라이트를 가지고 있으며 목표물을 뒤쫓고있다. 그건 모두 잘 작동합니다.cocos2d의 스프라이트에 대한 경계?
제 질문은 경계를 설정하는 방법입니까? 나는 그들이 화면에서 160 포인트 이상으로 움직일 수 있기를 원하지 않습니까?
내가보기에 모든 예제는 항상 box2d를 사용합니다. 엄격하게 cocos2d를 사용하는 방법이 있습니까?
- (void)addPlayers {
winSize = [CCDirector sharedDirector].winSize;
_officer = [[Officer alloc] initWithLayer:self];
_officer.position = ccp(winSize.width/2, 40);
_officer.tag = 1;
[_batchNode addChild:_officer];
_shotCaller = [[ShotCaller alloc] initWithTeam:2 layer:self];
//create spawn point
_shotCaller.position = ccp(100, 100);
[_batchNode addChild:_shotCaller];
NSString *gunName = [NSString stringWithFormat:@"gun.png"];
_gun = [CCSprite spriteWithSpriteFrameName:gunName];
_gun.anchorPoint = ccp(0.5, 0.25);
_gun.position = ccp(_shotCaller.contentSize.width/2, _shotCaller.contentSize.height/2 - 20);
[_shotCaller addChild:_gun];
[self moveRandom:_shotCaller];
NSMutableArray *team1GameObjects = [NSMutableArray arrayWithObject:_officer];
NSMutableArray *team2GameObjects = [NSMutableArray arrayWithObject:_shotCaller];
_gameObjects = [NSMutableArray arrayWithObjects:team1GameObjects, team2GameObjects, nil];
}
for(CCSprite *myNode in _gameObjects)
{
if (myNode.position.y == 160) {
NSLog(@"1");
[self checkCollision];
}
}
이 오류가 계속 발생합니까? - [__ NSArrayM 위치] : 인스턴스로 전송 된 인식 할 수없는 선택기 0x84597b0
내가 원하는 것은 sprite가 160이고 그 checkCollision 메소드가있는 것입니다. 위치를 160으로 설정합니다.
Ehhh, 당신의 스프라이트를 이동하는 어떤 코드를 만들 초과하지 않습니다 할 수있는 수직 위치를 제한 할 수 있습니다 너의 경계. – dqhendricks