Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9215825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:17:22+00:00 2026-06-18T02:17:22+00:00

I am trying to develop a game with multiple stages using cocos2d. In a

  • 0

I am trying to develop a game with multiple stages using cocos2d. In a level for example, I have 4 sprites, 2 white and 2 black. If the player hits the black sprites, the game is over, if he hits the white sprite, he wins. How can I implement a condition wherein if the player hits the white sprite, it checks if there are other white sprites present on the scene, if there is, the game continues. If there’s none, then he goes to the stage clear scene? I tried putting the sprites in two different arrays (arrayBlack and arrayWhite) but I’m stuck with how I’m gonna make the condition for the white sprites. Can anybody please give me an idea or suggestion or a tutorial that shows a good example for this?

UPDATE:
I kind of figured it out myself. Here’s my code:

-(id) init
{
if( (self=[super init]) ) {
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    self.isTouchEnabled = YES;

    //These are declared in the .h class
    blackArray = [[NSMutableArray alloc]init];
    whiteArray = [[NSMutableArray alloc]init];

    black1 = [CCSprite spriteWithFile:@"b1.png"];
    black1.position = ccp(100, 160);

    black2 = [CCSprite spriteWithFile:@"b2.png"];
    black2.position = ccp(105, 150);

    white = [CCSprite spriteWithFile:@"w1.png"];
    white.position = ccp(150, 150);

    white2 = [CCSprite spriteWithFile:@"w2.png"];
    white2.position = ccp(80, 160);

    [self addChild:black1 z:1 tag:1];
    [self addChild:black2 z:1 tag:2];
    [self addChild:white z:1 tag:3];
    [self addChild:white2 z:1 tag:4];

    [blackArray addObject:black1];
    [blackArray addObject:black2];
    [whiteArray addObject:white];
    [whiteArray addObject:white2];
}
return self;}

-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouch = [event allTouches];
UITouch *touch = [[allTouch allObjects]objectAtIndex:0];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector]convertToGL:location];

endTouch = location;
posX = endTouch.x;

//Minimum swipe length
posY = ccpDistance(beginTouch, endTouch);

//selectedSprite is a sprite declared in .h file
if(selectedSprite.tag == 1 || selectedSprite.tag == 2)
{
    //action here
}

if([whiteArray count] > 0)
{
    if(selectedSprite.tag == 3 || selectedSprite.tag == 4)
    {
        //action here
    }
    [whiteArray removeObject:selectedSprite];

    if([whiteArray count] == 0)
    {
        //Go to game over
    }
}}

This doesn’t look pretty but it works. Anyway, if there’s a better way to implement this than how I am currently doing it please let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:17:23+00:00Added an answer on June 18, 2026 at 2:17 am

    Make your arrays (arrayBlack and arrayWhite) mutable. Then,

    if(user hit sprite1)
    {
       if([arrayBlack containsObject:sprite1])
       {
         [arrayBlack removeObject:sprite1];
         // Game over
       }
       else
       {
         [arrayWhite removeObject:sprite1];
    
         if(arrayWhite.count>0)
         {
           // Continue game
         }
         else
         {
           // Stage clear scene
         }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to develop a game for iPhone by using Cocos2d. I need 'DRAG'
trying to develop web form using jquery. all i need is to have several
Trying to develop using MVVM: I have this Csla.PropertyStatus control that is created in
I am trying to develop a game like fruit Slayer . I have code
I'm playing around with cocos2d and box2d, trying to develop a game where tiles
I am trying to develop a Java 2D game and I have a problem
I'm trying to develop simple TCP , clinet/server game using Twisted and Pygame, but
I'm currently trying to develop a game using pygame and I'm having some problems
I'm trying to develop an Android 2D game using OpenGL ES that uses a
I'm trying to develop a simple 2D fighting game using OpenGL, and I'm stuck

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.