我可以使用cocos2d在iphone应用程序中显示图像的一部分吗? [英] Can i display a portion of an image in iphone application using cocos2d?

查看:96
本文介绍了我可以使用cocos2d在iphone应用程序中显示图像的一部分吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示部分图像不显示整个图像。首先显示完整图像,但延迟时间后显示此图像的一部分。我不明白我该怎么做。像我们可以通过修复Label的尺寸来显示文本部分。但在图像的情况下,我如何使用sprite或其他。

I want to display portion of image not to display the total image.At first display the full image but after a delay time display the a portion of this image. I can not understand how can i do this. Like we can display portion of text by fixing the dimension of Label.But in case of image how can i do that using sprite or other.

推荐答案

在CCSprite上设置纹理rect。

Set the texture rect on the CCSprite.

//create a sprite, e.g. myFile is 128x128 pixels
CCSprite* mySprite = [CCSprite spriteWithFile:@"myFile.png"];

//position it somewhere
[mySprite setPosition:ccp(xPos,yPos)];

//show only the first 64x64 square
[mySprite setTextureRect:CGRectMake(0, 0, 64, 64)];

//add it to the root
[self addChild:mySprite];

这篇关于我可以使用cocos2d在iphone应用程序中显示图像的一部分吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆