使用UITouch SpriteKit在数组中移动对象

时间:2013-11-28 19:32:07

标签: nsmutablearray scrollbar sprite sprite-kit

我正在尝试将SKSpritenode移动到一个数组中,就像滚动条一样,所有对象根据移动位置一起移动:

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch * touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];

    NSEnumerator *e = [_blockStream objectEnumerator];
    PBAIceBlock *block;
    while (block = [e nextObject]) 
    {
        //this says the expresion is not assignable
        block.position.y += location.y;
    }   
}

评论中说的是,我收到了错误,有人可以指出我正确的方向如何实现这样的事情吗? 在xcode 5中使用Sprite工具包?

1 个答案:

答案 0 :(得分:0)

解决方案是创建CGPoint来存储值。在touchesBegan中设置该值,然后:

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch * touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];

    int yOFFSET = location.y - _touchLocation.y ;
    NSLog(@"yOFFSET : %d", yOFFSET);
    NSEnumerator *e = [_blockStream objectEnumerator];
    PBAIceBlock *block;
    while (block = [e nextObject]) {
        CGPoint _center = block.position;
        _center.y += yOFFSET;
        block.position = _center;
    }
    _touchLocation = location;


}

发生此问题是因为您无法专门致电该职位。