我正在开发一个应用程序,我必须显示50到70个图像(精灵).我已经制作了一个滚动滚动所有这些图像,但我也想缩放这些图像我也一直在关注" http:// ganbarugames .com/2010/12/detected-touch-events-in-cocos2d-iphone / "这个教程.我想要完全相同的东西,但是那个教程只为一个精灵做了缩放的东西,但我想在每个精灵上做什么我该怎么办?请帮帮我?
-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchPoint = [touch locationInView:[touch view]];
touchPoint = [[CCDirector sharedDirector]convertToGL:touchPoint];
self.position = ccp((-(currentScreen-1)*scrollWidth)+(touchPoint.x-startSwipe),0);
--> NSArray *touchArray = [touches allObjects];
if([touchArray count] > 1)
{
UITouch *fingerOne = [touchArray objectAtIndex:0];
UITouch *fingerTwo = [touchArray objectAtIndex:1];
CGPoint pointOne = [fingerOne locationInView:[fingerOne view]];
CGPoint pointTwo = [fingerTwo locationInView:[fingerTwo view]];
pointOne = [[CCDirector sharedDirector] convertToGL:pointOne];
pointTwo = [[CCDirector sharedDirector] convertToGL:pointTwo];
float distance = sqrt(pow(pointOne.x - pointTwo.x, 2.0) + pow(pointOne.y - pointTwo.y, 2.0));
float scale = distance / [CCDirector sharedDirector].winSize.width * 5;
[backgroundScroll setScale:scale];
}
Run Code Online (Sandbox Code Playgroud)
这里是我正在使用的代码但它在代码中提到的箭头警告我'UITouch'可能不响应-allObjects'
请帮帮我........
最后,我得到了解决方案,就在这里
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(makepinch:)];
[[[CCDirector sharedDirector] openGLView] addGestureRecognizer:pinch];
Run Code Online (Sandbox Code Playgroud)
将他的代码放在init方法中,然后添加
-(void)makepinch:(UIPinchGestureRecognizer*)pinch
{
if(pinch.state == UIGestureRecognizerStateEnded)
{
currentScale = pinch.scale;
}
else if(pinch.state == UIGestureRecognizerStateBegan && currentScale != 0.0f)
{
pinch.scale = currentScale;
}
if(pinch.scale != NAN && pinch.scale != 0.0)
{
pinch.view.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4887 次 |
| 最近记录: |