accumFrame的坐标在SKShapeNode&中的含义是什么?我怎么能得到它们

时间:2014-11-17 08:33:49

标签: objective-c sprite-kit

我试图获得我称之为wallNode的spriteNode的位置。它有一个孩子的SKShapeNode,它是我现场的孩子。

wallNode init如下:

-(id) init:(CGPoint)firstPoint: (CGPoint)lastPoint{

if (self = [super init]) {

    self.name = @"wall";
    self.firstPoint = firstPoint;
    self.lastPoint = lastPoint;

    CGMutablePathRef pathToDraw = CGPathCreateMutable();
    CGPathMoveToPoint(pathToDraw, NULL, self.firstPoint.x, self.firstPoint.y);
    CGPathAddLineToPoint(pathToDraw, NULL, self.lastPoint.x, self.lastPoint.y);

    _wallShape = [[SKShapeNode alloc ]init];
    _wallShape.path = CGPathCreateCopy(pathToDraw);
    _wallShape.strokeColor = [SKColor redColor];
    _wallShape.lineWidth = 15;

    SKTexture *texture = [[SKTexture alloc] init];
    SKPhysicsBody * physicsBody = [SKPhysicsBody bodyWithEdgeFromPoint:firstPoint toPoint: lastPoint] ;

    self.physicsBody = [self updatePhysicsBody:physicsBody :@"wallNode"];

    [self addChild: _wallShape];
}

return self;
}

当我使用触摸事件选择Wall并尝试获得其位置时如下:

if([[ref getChoice] isEqualToString:@"Select"]){

        _positionInScene = [touch locationInNode:self];

        AbstractNode * touchedNode = (AbstractNode *)[self nodeAtPoint:_positionInScene];

        if([touchedNode isMemberOfClass:[SKShapeNode class]]){

            touchedNode = (AbstractNode*) touchedNode.parent;

        }
NSLog(@"touchedNodeX: %f, touchedNodeY:", [touchedNode position].x, [touchedNode position].y);

它给出位置x = 0.0000,位置Y = 0.0000。但是当我调试时,我注意到以下内容

<SKShapeNode> name:'(null)' accumulatedFrame:{{0, 0}, {184, 386}}

我确信{184,386}是我正在寻找的位置,但我不知道如何以编程方式获取它。有人可以帮忙吗?

0 个答案:

没有答案