UIImageView跳转

时间:2014-01-31 21:22:45

标签: ios socket.io

我每隔0.2秒调用一次这个方法,通过socket.io发送UIImageView位置:

- (void)update {
     CGPoint touchLocation = blue.center;
     if (!CGPointEqualToPoint(touchLocation, lastLocation) && !isAnimating) {
         NSDictionary *json = [NSDictionary dictionaryWithObjectsAndKeys:@(touchLocation.x), @"x", @(touchLocation.y), @"y", nil];
        [socketIO sendJSON:json];
        lastLocation = touchLocation;
    }
}

当其他设备收到此数据时,显示如下:

- (void)socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet {
    int x = [[packet.name valueForKey:@"x"] intValue];
    int y = [[packet.name valueForKey:@"y"] intValue];
    [UIView animateWithDuration:0.2 animations:^{
        [red setCenter:CGPointMake(x, y)];
    }];
}

即使我为动画制作动画,动画在接收方也非常紧张/跳跃。我会从touchesMoved:发送原始数据,但我发送了大量数据。我已经尝试将更新间隔更改为0.05,但我每5秒发送100个数据包每个播放器。这甚至是很多吗?有更好的方法吗?

0 个答案:

没有答案
相关问题