我如何简单地更改 cocos2d 中的精灵图像?图像、精灵、简单、cocos2d

2023-09-07 08:47:39 作者:人潮拥挤你不在ヾ

我试过了

[[CCTextureCache sharedTextureCache] addImage: @"still.png"];

但由于某种原因,我总是得到一个扭曲的图像.这很可能是因为我的图像分辨率不同,但对于这个应用程序,它们不能具有相同的分辨率.如何在不经历制作 spritesheet 或动画等复杂过程的情况下更改 sprite 的图像.

But I always end up with a distorted image for some reason. It's most likely because my images are not the same resolution, but for this app, they can't have the same res. How do I change the sprite's image without going through the complicated process of making a spritesheet or an animation or any of that.

推荐答案

urSprite = [CCSprite spriteWithFile:@"one.png"];
urSprite.position = ccp(240,160);
[self urSprite z:5 tag:1];

// Changing the image of the same sprite
[urSprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"two.png"]];