我在屏幕上有各种精灵,他们追逐他们的目标。这一切都很好。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 position]:发送到实例0x84597b0的无法识别的选择器
我想要做的就是使精灵停止在160处,并且checkCollision方法用于什么。只是将其位置设置为160.
Ehhh,任何代码移动你的精灵,让这个不会搬过去你的边界。 – dqhendricks 2013-03-21 19:52:46