嗨,
我已经开始开发一款 RPG 游戏。我使用放在 CCLayerPanZoom 上的等距样式图。现在我想在瓷砖地图上定位怨恨。当我单击时,我得到了新 Sprite 在地图上的位置的偏离位置。为什么?层与层之间是否存在滑动?有没有办法将地图附加到缩放图层,以便点击位置与地图上我想要放置新精灵的位置相对应。
请帮忙。
这是我的 init() 对于那些想要查看它的人,只需查看包含 Xcode 项目的 zip 即可。这是一个 Kobold2D 项目。我有相同的项目,但没有 CCLayerPanZoom 层。那里的定位工作完美。重要说明:当地图被拖动以使左边缘恰好位于 IPAD 模拟器左侧的边界上时,瓷砖放置几乎可以了。瓷砖放置在正确的位置。
- (id) init
{
if ((self = [super init]))
{
//touches enables
self.isTouchEnabled = YES;
//instantiate the PanZoomLayer
panZoomLayer = [CCLayerPanZoom node];
//seting poperties for the pan zoom layer
panZoomLayer.maxScale = 1.0f;
panZoomLayer.minScale = 0.2f;
panZoomLayer.maxSpeed = 100.0f;
panZoomLayer.maxTouchDistanceToClick = 1000.0f;
panZoomLayer.panBoundsRect = CGRectNull;
panZoomLayer.mode = kCCLayerPanZoomModeSheet;
//add the zoom layer to the CCLayer
[self addChild: panZoomLayer z:-1];
//if I uncoment this it thros me an error by ccTouchesEnded
//It has to be commented like this
//panZoomLayer.delegate = self;
self.map = [CCTMXTiledMap tiledMapWithTMXFile:@"isometric-no-offset.tmx"];
_map.anchorPoint = ccp(0,0);
_map.scale = CC_CONTENT_SCALE_FACTOR();
layer = [_map layerNamed:@"Ground"];
layer.visible = YES;
[panZoomLayer addChild: _map
z :-1
tag:kTileMapTag];
// create and initialize a Label
CCLabelTTF *label = [CCLabelTTF labelWithString: @"Zooming and scroling Demo"
fontName: @"Marker Felt"
fontSize: 30];
label.scale = 0.7f; //< to be visible on iPod Touch screen.
label.color = ccBLUE;
// add the label as a child to this Layer
[panZoomLayer addChild: label
z: 1
tag:kLabelTag];
_player = [CCSprite spriteWithFile:@"ninja.png"];
//map size
mapHeight = _map.contentSize.height;
mapWidth = _map.contentSize.width;
//screen size
CGSize screenSize = [[CCDirector sharedDirector] winSize];
screenCenter = CGPointMake(screenSize.width / 2, screenSize.height / 2);
//Hide/Show character
[_player setVisible:YES];
_player.position = ccp(300, 400);
[panZoomLayer addChild:_player z:2];
//dot initialization
self.dot = [CCSprite spriteWithFile:@"d2.png"];
//_dot. position = ccp(200,200);
[_map addChild:dot z:3];
panZoomLayer.mode = kCCLayerPanZoomModeSheet;
panZoomLayer.minScale = 0.6f;
panZoomLayer.maxScale = 2.0f;
panZoomLayer.rubberEffectRatio = 1.1f;
//test different scren reshapes
//the zooming and scroling works also without any of the following methods
//simple. until now the most convenient
[self updateForScreenReshape1];
//ruber. means center on screen. zoom out more in as previous
//[self updateForScreenReshape2];
//with zones. zoom out more and in less
//[self updateForScreenReshape3];
}
return self;
} gBoy 宝贝黑客
帖子:8 加入时间:2012 年 5 月 10 日星期四晚上 7:26 已感谢:0 次 已感谢:0 次