我正在使用一个动画块来遍历一组 .png 图像,使其看起来像一个角色正在屏幕上行走。但是,当我缩小图像时,图像的质量会变得模糊。目前我正在用 19 张图像测试动画,所有图像的分辨率均为 371 x 379。但是,我需要它们在屏幕上看起来更小,所以我在我的应用程序上将它们缩放到 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 中的所有内容并查看互联网上的每个论坛时使用一些技巧.