我正在使用动画块来迭代一组.png图像,使其看起来像一个角色正在屏幕上行走。但是,当我缩小图像时,图像的质量会模糊。目前我正在使用371 x 379分辨率的19张图像测试动画。但是,我需要它们在屏幕上看起来更小,所以我在我的应用程序上将它们缩放到64 x 65。当我这样做时,线条有点扭曲,当我暂停游戏时,你可以真正地告诉你图像质量不是它应该的位置。下面是我用来迭代图像的代码。任何帮助将不胜感激。
[UIImageView animaiteWithDuration: 3.0
delay: 0
options: UIViewAnimationOptionBeginFromCurrentState
animations: ^{
CABasicAnimation *mover = [CABasicAnimation animationWithKeyPath:@"position"];
// Get the current presentationLayer of the object
CALayer *currentLayer = self.layer.presentationLayer;
// Get the current point of the presentationLayer
CGPoint currentPoint;
currentPoint.x = currentLayer.position.x;
currentPoint.y = currentLayer.position.y;
// Set the new point for the object to move to
CGPoint newPoint;
newPoint.x = currentLayer.position.x - 50;
newPoint.x = currentLayer.position.y;
// Set the from and to values of the animation
[mover setFromValue: [NSValue valueWithCGPoint:currentPoint]];
[mover setToValue: [NSValue valueWithCGPoint:newPoint]];
[mover setDuration:3.0]; // Set the duration of the mover animation
// Create the nine-teen UIImages for the array
UIImage *image1 = [UIImage imageNamed:@"img1"];
UIImage *image2 = [UIImage imageNamed:@"img2"];
UIImage *image3 = [UIImage imageNamed:@"img3"];
UIImage *image4 = [UIImage imageNamed:@"img4"];
UIImage *image5 = [UIImage imageNamed:@"img5"];
UIImage *image6 = [UIImage imageNamed:@"img6"];
UIImage *image7 = [UIImage imageNamed:@"img7"];
UIImage *image8 = [UIImage imageNamed:@"img8"];
UIImage *image9 = [UIImage imageNamed:@"img9"];
UIImage *image10 = [UIImage imageNamed:@"img10"];
UIImage *image11 = [UIImage imageNamed:@"img11"];
UIImage *image12 = [UIImage imageNamed:@"img12"];
UIImage *image13 = [UIImage imageNamed:@"img13"];
UIImage *image14 = [UIImage imageNamed:@"img14"];
UIImage *image15 = [UIImage imageNamed:@"img15"];
UIImage *image16 = [UIImage imageNamed:@"img16"];
UIImage *image17 = [UIImage imageNamed:@"img17"];
UIImage *image18 = [UIImage imageNamed:@"img18"];
UIImage *image19 = [UIImage imageNamed:@"img19"];
// Populate the animation array
NSArray *walkingAnimation = [NSArray arrayWithObjects: img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14, img15, img16, img17, img18, img19, nil];
[self setAnimationImages: walkingAnimation]; // Set the animation images to the array
[self setAnimationRepeatCount:3]; // Repeat the animation every second
[self setAnimationDuration:1.0];
[self startAnimating]; // Start the animation
[[self layer] addAnimation:mover forKey:@"position"]; // Add the mover animation to the layer
[UIImageView commitAnimations];
[[self layer] setPosition:newPoint]; // Set the position to avoid bounce back
} completion:nil];
因此,如果有人能告诉我是否需要做一些额外的事情来保持图像不会扭曲,或者可能是图像本身,我可以在阅读Apples API中的所有内容并查看每个论坛时使用一些提示在互联网上。
答案 0 :(得分:3)
您的问题应该与代码无关。您正在将图像调整为不同的宽高比。您应该非常小心调整图像大小,因为图像会自然模糊。
您最好的选择是创建准确(清晰)的图像,目的是根据您使用它们的尺寸。