0

So I'm creating a game with cocos2d, and alot of my scenes (not all, but alot), will have sort of a "scoreboard" you could call it, and they will have the basic principals. I was wondering, how could I make it so the "game scenes" could all implement the scoreboard?

I was thinking this could use something like Categories, but I'm fairly new to iOS/obj-c so I don't know if that's the right approach.

In Java, I could probably just make all the scenes subclasses and have the superclass do all of the scoreboard handling, but I have no idea how to do that in iOS/obj-c.

Thanks

4

2 に答える 2

1

サブクラス CCNode または適切なその他のクラス (CCScene、CCLayer、実際には関係ありません)。このクラスに MyScoreboard という名前を付けます。スコアボード ノードにノードを追加して配置することにより、他のシーンと同じようにスコアボード ノードを設計します。

次に、スコアボードが必要な場所でインスタンスを作成し、ノード階層に追加します。

MyScoreboard* scoreboard = [[MyScoreboard alloc] init];
[self addChild:scoreboard];

必要に応じて、パラメーター (initWithScore:Player:WhatNot:) を使用して初期化を修正します。

于 2012-05-21T21:26:24.603 に答える
0

ここでも同じソリューションを使用できます。CCSceneのサブクラスを作成します。次に、そこにスコアロジックを実装します。シーンのすべてのサブクラスがこれらのメソッドを呼び出すことができます。たとえば、メソッドshowScore/hideScoreまたはsmthelseを作成できます。そこで、スコアの印象を現在のシーンに構築および追加/削除できます。

于 2012-05-21T15:18:36.380 に答える