我有一张平铺地图。我用cocos2D。等轴测图有一个CCLayerPanZoom。用于缩放和滚动。现在我想在我按下它的位置添加一个瓷砖。这是行不通的。它将瓷砖插入错误的位置。
是否与地图缩放有关(缩放和滚动是可行的)。?
-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event{
touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
CGPoint playerPos = _player.position;
CGPoint diff = ccpSub(touchLocation, playerPos);
if (abs(diff.x) > abs(diff.y)) {
if (diff.x > 0) {
playerPos.x += self.map.tileSize.width;
} else {
playerPos.x -= self.map.tileSize.width;
}
} else {
if (diff.y > 0) {
playerPos.y += self.map.tileSize.height;
} else {
playerPos.y -= self.map.tileSize.height;
}
}
//player.position = playerPos; // Todo: Trymove
if (playerPos.x <= (self.map.mapSize.width * self.map.tileSize.width) &&
playerPos.y <= (self.map.mapSize.height * self.map.tileSize.height) &&
playerPos.y >= 0 &&
playerPos.x >= 0 ) {
[self setPlayerPosition:playerPos];
}
if([TileMapLayer isOnTheMapMoreRestrictive:touchLocation map:self.map mapsize:self.map.mapSize.width] )
[self plantObject:touchLocation];
else
CCLOG(@"Outside possition");
[self setDotPosition: [self tilePosFromLocation:touchLocation tileMap:self.map]];
}
-(void)plantObject:(CGPoint) location{
punkt = [CCSprite spriteWithFile:@"tree.png"];
punkt. position = [self tilePosFromLocation:location tileMap:self.map];
[_map addChild:punkt z:4];
}