我如何简单地更改 cocos2d 中的精灵图像? [英] How do i simply change a sprite's image in cocos2d?
本文介绍了我如何简单地更改 cocos2d 中的精灵图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试过了
[[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"]];
这篇关于我如何简单地更改 cocos2d 中的精灵图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文