开发者

problems when working on a game just like fruit ninja

i want to make a similar game to fruit ninja. at first I have: a GameScene(a multi layer scene which adds different GameModeLayers and a PauseLayer as children), a ClassicGameModeLayer, which is only a container for sprite iVar of Fruit class. isTouchEnabled = NO, and no game logic behind. a Fruit class, which contains a CCSprite *fruit and int score. conform to CCTouchDelegate and handles all the game logic behind. (just like the sample Spider code in book "Learn.iPhone.and.iPad.Cocos2D.Game.Development")

Then i have a problem. i can only slice one fruit at a time and touch is available only after the fruit shows up.

i have 2 other models designed today. one is to put the touch handling code in ClassicGameModeLayer, and also contains a CCArray of Fruit, keep the movement of Fruit inside Fruit class.

and the other model is to create a CCArray of CCSprite fruits inside the Fruit class, with all the game logic(ClassicGameLayer still does nothing)

i don't know if they are achiev开发者_Go百科able. i am currently coding the first one and crashes somehow. you guys have any better ideas? is there a common approach to this?


The touch only shows up after the fruit appears because the fruit is the only object that responds to touches. Your app can't respond until the fruit exists.

Take a look at Ray Wenderlich's tutorials for creating Cocos2D-iPhone apps.

My suggestion is this:

  • have the layer respond to touches
  • create a "FruitManager" Singleton that holds all the fruit
  • when you touch the screen, [[FruitManager sharedFruitManager] allFruits] will give you a list of the fruits to see if the user has "touched" through one of them.

Ray's Wack-A-Mole game should get you close to what you're doing. His Ninja/Ghost game also has rules for intercepting projectiles - just use touches instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜