我还是 cocos2d 的新手,我有这个问题,当我使用 ccp 坐标时,即使我移动到下一个屏幕,它也会保持在相同的位置。我得出的结论一定是我没有使用瓷砖坐标。所以我需要一些帮助转换。
- (CGPoint)tileCoordForPosition:(CGPoint)position {
float x = floor(position.x / map.tileSize.width);
float levelHeightInPixels = map.mapSize.height * map.tileSize.height;
float y = floor((levelHeightInPixels - position.y) / map.tileSize.height);
return ccp(x, y);
}
-(CGRect)tileRectFromTileCoords:(CGPoint)tileCoords {
float levelHeightInPixels = map.mapSize.height * map.tileSize.height;
CGPoint origin = ccp(tileCoords.x * map.tileSize.width, levelHeightInPixels - ((tileCoords.y + 1) * map.tileSize.height));
return CGRectMake(origin.x, origin.y, map.tileSize.width, map.tileSize.height);
}
这就是我用来将常规坐标转换为瓦片地图坐标的方法。
现在我正试图在特定位置产生一个敌人(0,0)
-(void)addsaw{
CCSprite *saw = [CCSprite spriteWithFile:@"saw.png"];
// Determine where to spawn the target along the Y axis
CGSize winSize = [[CCDirector sharedDirector] winSize];
int minY =saw.contentSize.height/2;
int maxY = winSize.height - saw.contentSize.height/2;
int rangeY = maxY - minY;
int actualY = ( rangeY) + minY;
//THIS IS THE PROBLEM RIGHT HERE
saw.position = ccp(0,0);
[self addChild:saw];
// Create the actions
id actionMove = [CCMoveTo actionWithDuration:actualDuration
position:ccp(-saw.contentSize.width/2, actualY)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self
selector:@selector(spriteMoveFinished2:)];
[saw runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
saw.tag = 1;
[_saws addObject:saw];
}
如何更改我的addsaw的ccp,以便我可以让它在瓷砖(0,0)而不是cocos2d常规(0,0)产生