Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 从CCSpriteBatchNode更改精灵纹理_Objective C_Cocos2d Iphone - Fatal编程技术网

Objective c 从CCSpriteBatchNode更改精灵纹理

Objective c 从CCSpriteBatchNode更改精灵纹理,objective-c,cocos2d-iphone,Objective C,Cocos2d Iphone,我正在尝试更改从SpriteBatchNode创建的精灵的纹理 [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA4444]; spritesBgNode = [CCSpriteBatchNode batchNodeWithFile:@"playingCards.pvr.ccz"]; [self addChild:spritesBgNode]; [[CCSpriteFrameCache sharedSprit

我正在尝试更改从SpriteBatchNode创建的精灵的纹理

[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA4444];

spritesBgNode = [CCSpriteBatchNode batchNodeWithFile:@"playingCards.pvr.ccz"];
[self addChild:spritesBgNode];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"playingCards.plist"];
我搜索并找到了使用

Texture2D *texture = [[Texture2D alloc] initWithImage:myUIImage]

[sprite setTexture: texture];
所以我的问题是:如何从batchNode文件中获取图像?或者我是否使用另一种方法获取对playingCards.pvr.ccz文件中图像的引用

更新

首先,感谢您的回复。因此,我使用您提供的代码片段创建了具有国王图像的mySprite。但是我想改变精灵的纹理来显示卡片的背面(这样它可以面朝上或面朝下播放),我在CCSpriteBatchNode中有两个图像

[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA4444];

spritesBgNode = [CCSpriteBatchNode batchNodeWithFile:@"playingCards.pvr.ccz"];
[self addChild:spritesBgNode];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"playingCards.plist"];
但正如您指出的“您无法从batchNode获取图像”,因此我不能使用[[Texture2D alloc]initWithImage:myUIImage]

所以我要改变精灵的形象,从正面朝上到正面朝下


谢谢

如果要在屏幕上显示.pvr.ccz文件中的图像,请添加以下代码:

CCSprite * mySprite = [CCSprite spriteWithSpriteFrameName: @"name of sprite frame"];
[spritesBgNode addChild: mySprite];
基本上,要显示batchNode的某些部分,需要向其中添加精灵。精灵帧的名称位于添加到帧缓存的.plist文件中

无法从batchNode获取图像。UIImage是iphoneapi类型的图像,而不是cocos2d。在cocos2d中,为了方便起见,提供了
initWithImage:(UIImage*)image

如果使用
[[Texture2D alloc]initWithImage:myUIImage]
,则UIImage用于创建NSData对象,并在内部调用[texture initWithData:data]。图像未存储以供以后使用

更新

在这种情况下,精灵充当“batchNode视图”。要查看批处理节点的其他部分,请更改精灵的框架

[mySprite setDisplayFrame:
    [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"back of card"]]];

如果要在屏幕上显示.pvr.ccz文件中的图像,请添加以下代码:

CCSprite * mySprite = [CCSprite spriteWithSpriteFrameName: @"name of sprite frame"];
[spritesBgNode addChild: mySprite];
基本上,要显示batchNode的某些部分,需要向其中添加精灵。精灵帧的名称位于添加到帧缓存的.plist文件中

无法从batchNode获取图像。UIImage是iphoneapi类型的图像,而不是cocos2d。在cocos2d中,为了方便起见,提供了
initWithImage:(UIImage*)image

如果使用
[[Texture2D alloc]initWithImage:myUIImage]
,则UIImage用于创建NSData对象,并在内部调用[texture initWithData:data]。图像未存储以供以后使用

更新

在这种情况下,精灵充当“batchNode视图”。要查看批处理节点的其他部分,请更改精灵的框架

[mySprite setDisplayFrame:
    [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"back of card"]]];

我更新了下面的答案以反映您更新的问题,请您指出下面的答案是否解决了问题?我更新了下面的答案以反映您更新的问题,请您指出下面的答案是否解决了问题?