制作 CCSprite 的副本
我正在寻找对我的 CCSprite 进行子类化的许多重复或克隆。这是我游戏中的敌人角色,我需要无数次复制它。我该怎么做?
有人告诉我应该创建一个 EnemyFactory 类,将敌人分组,并将它们存储起来以供游戏中的后续关卡使用。
如果有人能为我解释一下,我将不胜感激:)
I'm looking to make many duplicates, or clones, of my CCSprite that's been subclassed. It's an enemy character in my game, and I will need to duplicate it countless times. How can I do this?
I've been told I should make an EnemyFactory class that makes the enemies in groups, and stores them for later levels in the game.
If someone could please explain this for me, that would be greatly appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,听起来您想要一种机制来跟踪您正在创建的所有敌人,并观察/调整他们的位置?
我建议将新创建的敌人添加到 NSMutableArray 中,如下所示:
然后,当您想要查看/调整敌人精灵位置时 - 例如在主游戏循环中,当它们攻击您的英雄时,请使用以下内容:
查看官方 cocos2d 论坛进行此类精灵管理的一些好的便捷方法:
http://www.cocos2d-iphone.org/forum/topic/5971
Sure, it sounds like you want a mechanism to track all the enemies you are creating, and watch/adjust their locations?
I suggest adding newly created enemies to a NSMutableArray like so:
Then when you want to look at/adjust the enemy sprite positions- say on the main game loop as they are attacking your hero, use the following:
Check out the official cocos2d forums for some good convience methods to do this kind of sprite management:
http://www.cocos2d-iphone.org/forum/topic/5971
这是我用来创造敌人的一个例子。
当您想要创建敌人时,在图层中添加以下内容:
Gamelayer.m
然后基于 CCSprite 创建敌人类:
EnemySpriteClass.h
EnemySpriteClass.m
如果您在动态创建敌人时遇到性能问题,您可以随时批量创建它们然后当您希望它们出现在屏幕上时调用 [self addchild:enemy] 。
Here is an example of what I use to create enemies.
Within your layer add the following when you want enemies to be created:
Gamelayer.m
And then create an enemey class based on CCSprite:
EnemySpriteClass.h
EnemySpriteClass.m
If your having performance issues creating them on the fly, you can always batch create them and then call [self addchild:enemy] when you want them on screen.