I am porting bits of the game engine to another game code’s and I have two concerns.
The code:
-(void) checkForBulletCollisions
{
Enemy* enemy;
CCARRAY_FOREACH([batch children], enemy)
{
if (enemy.visible)
{
BulletCache* bulletCache = [[GameScene sharedGameScene] bulletCache];
//etc etc
The GameScene in the project I am porting this code to is not a singleton like the GameScene is in the above code.
Here is the GameScene’s interface code:
@interface GameScene : CCScene
+(void) newGame:(NSString*)levelFile;
-(void) reloadGame:(NSString*)levelFile;
@end
When porting the top lines of code I replaced the top line of code with:
BulletCache* bulletCache = [[GameScene node] bulletCache];
Am I on the right track?
As hiepnd stated – the node method creates a new autoreleased instance. The code you are porting however is calling a singleton. I’m going to assume that the singleton is the ‘current scene’ – and therefore your task in porting is to find the top node in the node hierarchy – confirm that it is indeed of Class GameScene, and then retrieve yur reference to the bulletCache from it.
The current scene can be retrieved from the director as follows: