简体   繁体   中英

Sprite Kit: Count of SKSpriteNodes on screen

This seems like a really easy question, but I can't seem to find the answer anywhere. I am making a game using Sprite Kit, and I would like to get the count of how many SKNodes I currently have on the screen. I can see the count on the bottom right corner in my debugging information, but I'm not sure how to access it as an integer I can use to program with. Any suggestions?

Apple docs say, "An SKScene object represents a scene of content in Sprite Kit. A scene is the root node in a tree of Sprite Kit nodes..."

So, use the following statement in your SKScene class, see if it outputs the correct number.

NSLog(@"%lu", (unsigned long)[self.children count]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM