如何更改cocos2d精灵中的图像从数组? [英] How to change the image in a cocos2d sprite from an array?

查看:311
本文介绍了如何更改cocos2d精灵中的图像从数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改来自数组的sprite正在显示的图像。这里是我使用的代码:

 ((Sprite *)[enemiesArray objectAtIndex:index])image = baseImage; 

我收到错误讯息:

 错误:在结构或联合体中请求成员'image'

我做错了什么?



感谢您阅读。

解决方案

我不认为这是做到这一点的方法。
而不是你应该调用一个init方法:



- (id)initWithCGImage:(CGImageRef)image;



- (id)initWithTexture:(Texture2D *)tex;



- (id)initWithFile:(NSString *)imageFile;

在我的游戏中,我做了不同的,我有一个类为我的对象称为'Zed',我也存储在一个数组。它有一个精灵作为一个字段,如果我想改变图像,我交换整个精灵,并确保我隐藏旧的,显示新的。


I'm trying to change the image that a sprite from an array is displaying. Here is the code I'm using:

((Sprite *)[enemiesArray objectAtIndex:index]).image = baseImage;

I get the error message:

error: request for member 'image' in something not a structure or union

What am I doing wrong?

Thanks for reading.

解决方案

I don't think that this is the way to do this. Rather than that you should call one of the init methods:

- (id) initWithCGImage:(CGImageRef)image;

- (id) initWithTexture:(Texture2D*) tex;

- (id) initWithFile:(NSString *) imageFile;

In my game i do this differently, i have a class for my object called 'Zed' which i also store in an array. It has a sprite as a field and if i want to change the image i swap the whole sprite and make sure i hide the old and show the new one.

这篇关于如何更改cocos2d精灵中的图像从数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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