Comments (12)
The reason I didn't implement it recursively was that the getChildByTag wasn't recursive. But, I think it's can be reasonable to expect it to be.
from cocos2d-objc.
Or there could be a getChildByTag:(int)tag recursively:(bool)isRecursive
and similar for searching by name. At least that's what I did in few of my extensions.
from cocos2d-objc.
Hmm. I was on the fence about it. Looking at the docs for the similar GameObject.Find() method in Unity I found this:
"This function is most useful to automatically connect references to other objects at load time (...)"
I usually avoid using that feature in Unity since it's so easy to make bugs by simple misspellings of strings scattered around the project. I guess I do use it to find child objects in things that I instantiate, and that's a use case that will carry over to SpriteBuilder pretty well I think. So I guess I would say making it recursive makes sense.
Unity also lets you use a path-like string too. ex: "ship/thruster1". That might be something to consider for the future, but it's not really a trivial feature to add.
from cocos2d-objc.
I like getChildByTag:(int)tag recursively:(bool)isRecursive
more than having two versions of the method, since no one will ever use the wrong one accidentally. And most importantly, it clears up incorrect assumptions, like the one I had. I don't have a huge preference other than that.
from cocos2d-objc.
Using more than one version is very natural for Objective-C programmers. They will definitely see both, and the amount of confusion will be at least less than addChild:z:tag:
, since that method has 3 versions.
The reason I would push for two versions is the convenience of using methods with single arguments in objective-c. When you so a CCCallFunc, you can pass a single object, so if the method requires more than one objects, it cannot be used. The same applied to the Objective-C methods performSelecter:
.
from cocos2d-objc.
I like getChildByTag:(int)tag recursively:(bool)isRecursive
too. I think that one method would be enough, Cocos2d often adds too many aliases for the same thing, which imho makes things harder to use not easier.
from cocos2d-objc.
Here's what I whipped together:
At the moment it has a recursive getChildByTag:(int)tag recursively:(bool)isRecursive
and a getChildByTag:(int)tag recursively:(bool)isRecursive
. I'll wait for a few more opinions before deciding if we want both.
(Hey look, there's unit tests in there!)
from cocos2d-objc.
@vlidholt Agreed. I feel like in many cases it's common to have many aliased methods because they were added over time. Unless the method has 5 arguments, it's a lot cleaner to have fewer methods if each one isn't trying to do too much.
from cocos2d-objc.
@andykorth So, there was a decision made to replace the tag property by a name property, so I don't think we should reinstate the tag. In the link you sent I don't see any tags so I am happy with that! Just double check that the old method isn't used inside Cocos somewhere.
from cocos2d-objc.
Oops, I'm not sure how the word tag snuck into my github comment. Definitely names.
I'll wrap this up today and go with one method instead of two. Thanks!
from cocos2d-objc.
Shouldn't this have a default for existing behaviour instead of having to add 'recursively' all the time?
from cocos2d-objc.
The overall consensus from earlier in the discussion was that we should avoid adding method aliases for new methods. In this case the method wasn't completely new (tag -> name). With auto-complete, Xcode does most of the typing for you at least?
from cocos2d-objc.
Related Issues (20)
- Make userInteractionEnabled property cascadable
- Shader uniform array support HOT 1
- Touches are retained HOT 1
- Multi-instance API discussion HOT 1
- MAC how to install the cocos2d - objc 3.5.0 HOT 1
- CCShader needs to separate vsh/fsh name HOT 1
- website's forum doesn't work HOT 2
- CCDirectorIOS 'drawScene' causes crash HOT 2
- Could you please upgrade the cocos2d-objc version on cocoapod? HOT 4
- How to create two separate views respectively according to different scenarios? HOT 1
- Stuck in adding Ripple effect on an image with CCSpriteGrid extension. HOT 1
- CCDirectorIOS 'didReceiveMemoryWarning' crash
- How to include Cocos2D to an already existing iOS project? HOT 1
- CCRendererBasicTypes.m CCBlendModeCache HOT 1
- EXC_BAD_ACCESS of CCRenderBufferSetVertex HOT 3
- Project Site is not worked HOT 4
- Alternative for obsolete OpenGL calls?
- Credit card
- Vertices pages boundary overlap
- fk,放一个8年代码在这干嘛 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cocos2d-objc.