iphone - 使用 ccTouchesMoved 方法 move CCCamera? (cocos2d、iPhone)

标签 iphone camera cocos2d-iphone move

所以我得到了这个工作:

-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *myTouch = [touches anyObject];
    CGPoint location = [myTouch locationInView:[myTouch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

        for( UITouch *touch in touches ) {
            CGPoint touchLocation = [touch locationInView: [touch view]];   
            CGPoint prevLocation = [touch previousLocationInView: [touch view]];    

            touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
            prevLocation = [[CCDirector sharedDirector] convertToGL: prevLocation];

            CGPoint diff = ccpSub(touchLocation,prevLocation);
            [self setPosition: ccpAdd(self.position, diff)];
        }
}

我可以用手指 move 图层,但我想 move cccamera,但我没有任何 cccamera 的经验。

谁能帮我吗?

非常感谢 祝你有美好的一天

:)

最佳答案

这就是我正在使用的...这种 move 相机的实现是我在 cocos2d 论坛上找到的。

-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *myTouch = [touches anyObject];
    CGPoint location = [myTouch locationInView:[myTouch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    for( UITouch *touch in touches ) {
        CGPoint touchLocation = [touch locationInView: [touch view]];   
        CGPoint prevLocation = [touch previousLocationInView: [touch view]];    

        touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
        prevLocation = [[CCDirector sharedDirector] convertToGL: prevLocation];

        CGPoint diff = ccpSub(touchLocation,prevLocation);
        [self setPosition: ccpAdd(self.position, diff)];

        // Get the camera's current values.
        float centerX, centerY, centerZ;
        float eyeX, eyeY, eyeZ;
        [self.camera centerX:&centerX centerY:&centerY centerZ:&centerZ];
        [self.camera eyeX:&eyeX eyeY:&eyeY eyeZ:&eyeZ];

        // Increment panning value based on current zoom factor.
        diff.x = 2 * diff.x * (1+(eyeZ/832));
        diff.y = 2 * diff.y * (1+(eyeZ/832));

        // Round values to avoid subpixeling.
        int newX = centerX-round(diff.x);
        int newY = centerY-round(diff.y);

        // Set values.
        [self.camera setCenterX:newX centerY:newY centerZ:0];
        [self.camera setEyeX:newX eyeY:newY eyeZ:eyeZ];
    }
}

关于iphone - 使用 ccTouchesMoved 方法 move CCCamera? (cocos2d、iPhone),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5285020/

相关文章:

iphone - iphone 上 Bootstrap 响应式设计中的页面宽度

ios - 在容器 View 内的选项卡栏 Controller 内委派来自 View Controller 的信息

ios - 使用大型 UIImage 数组时的内存问题导致崩溃(快速)

iphone - UIGestureRecognizer不会旋转 Sprite - Cocos2d

c++ - box2d:在 ResetMassData 上获取 SIGABRT,b2Assert(m_I > 0.0f) - 中心惯性、质心

iphone - 无法显示异步加载的纹理

iphone - 在后台线程上解除分配

iphone - UITabBarController 和 UINavigationController

java - 暂停时保持相机 Activity

java - 使用 jBullet 的 LWJGL 第一人称相机