objective c - Fastest way to copy or create a CCNode game object in cocos2d-iphone? -


background: i'm developing game iphone/ipad using cocos2d-iphone. our engine provides ability level designer create new bad-guys defining number of properties such speed, ai, weapons , main sprite texture in .plist files.

problem: currently, build nsdictionary of of prototypes before level starts. each entity store class name , nsdictionary describing parameters required build new instance of entity. create instance of each prototype @ load time precache textures destroy immediately. when new bad guy spawns, use stored nsdictionary , pass init method (stripped of error checking brevity);

ikprototype* prototype = [prototypes objectforkey:prototypeid];  ikbaseentity* entity = [[[nsclassfromstring([prototype prototypeclass]) alloc] init] autorelease]; [entity setprototypeid:prototypeid]; [entity parseparameters:[prototype parameters]]; return entity; 

now, works treat - creating number of bullets in same frame causes noticeable slow down (a frame or 2 dropped) engine parses parameters (sometimes 20-30 values). however, they're same every time , change when added world (which happens later).

question: efficient method store prototype object later duplicates spawned. serialization/deserialization work subclass of ccnode, , quicker i'm doing? better store copy of final object in prototype class, , 'deep copy' of object spawning? have worry cctexture references if did this? please briefly explain required steps proposed solution.

have been trying think of efficient method solving problem while. i'm wondering if there's method i've not thought of above might better? reading far.

one approach i've taken pre-create bunch of objects while loading resources first time (say in init), co-opting 1 of resources @ run-time changing parameters , moving array of inactive objects active objects.

you might not have created enough, of course, if these objects sharing textures, etc. might want create them members of ccbatchnode anyway , make more efficient draw many of them.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -