Giter VIP home page Giter VIP logo

Comments (12)

vlidholt avatar vlidholt commented on June 15, 2024

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.

dominik-hadl avatar dominik-hadl commented on June 15, 2024

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.

slembcke avatar slembcke commented on June 15, 2024

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.

andykorth avatar andykorth commented on June 15, 2024

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.

 avatar commented on June 15, 2024

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.

vlidholt avatar vlidholt commented on June 15, 2024

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.

andykorth avatar andykorth commented on June 15, 2024

Here's what I whipped together:

andykorth@2b08f0e

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.

slembcke avatar slembcke commented on June 15, 2024

@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.

vlidholt avatar vlidholt commented on June 15, 2024

@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.

andykorth avatar andykorth commented on June 15, 2024

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.

cocojoe avatar cocojoe commented on June 15, 2024

Shouldn't this have a default for existing behaviour instead of having to add 'recursively' all the time?

from cocos2d-objc.

slembcke avatar slembcke commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.