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 9182711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:37:30+00:00 2026-06-17T18:37:30+00:00

I am trying to make a game in cocos2d wherein I have sprites dropping

  • 0

I am trying to make a game in cocos2d wherein I have sprites dropping from the top of the screen. Now, once the sprite is tapped, it should move back up. This works for me just fine but, there are some instances wherein the sprite would go back down after it goes off the screen. Also, my sprites don’t disappear once they reach a certain y-axis position on the screen. Here’s part of my code

-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint loc = [[CCDirector sharedDirector]convertToGL:[touch locationInView:[touch view]]];

CGRect rect = CGRectMake(sprite.position.x - (sprite.contentSize.width/2), sprite.position.y - (sprite.contentSize.height/2), sprite.contentSize.width, sprite.contentSize.height);

if(CGRectContainsPoint(rect, loc))
{
    [sprite runAction:[CCCallFuncN actionWithTarget:self selector:@selector(spriteCaught)]];
}}

-(void)spriteCaught
{
//currentPos is an integer to get the current position of the sprite
id moveUp = [CCMoveTo actionWithDuration:1 position:ccp(currentPos, 500)];
[sprite runAction:[CCSequence actions:moveUp, nil]];
if(sprite.position.y >= 480)
{
    [self removeChild:sprite cleanup:YES];
}}

Also, I’m not sure if my syntax is correct but my conditional statement (The one that checks the position in the y-axis of the sprite) doesn’t work either. How do I go about fixing this? Any help and suggestion is greatly appreciated

  • 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-17T18:37:31+00:00Added an answer on June 17, 2026 at 6:37 pm

    Instead of manual rect, use sprite’s bounding box.

             if(CGRectContainsPoint([sprite boundingBox], loc))
    

    Also update spriteCaught function.

    -(void)spriteCaught
    {
        CGSize s = [[CCDirector sharedDirector] winSize];
    
        float dest_y = s.height+sprite.contentSize.height*0.5f; //assumed ur sprite's anchor y = 0.5
    
        //currentPos is an integer to get the current position of the sprite
        id moveUp = [CCMoveTo actionWithDuration:1 position:ccp(sprite.position, dest_y)];
        id calBlokc = [CCCallBlockN actionWithBlock:^(CCNode *node)
        {
            //here node = sprite tht runs this action
            [node removeFromParentAndCleanup:YES];
        }];
        id sequence = [CCSequence actions:moveUp, calBlokc, nil];
    
        [sprite runAction:sequence];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make the game Asteroids. My issue I have right now,
I am just messing around trying to make a game right now, but I
Trying to make simple minesweeper game in python, but have one problem. I have
I am trying to make a simple game in C#/XAML. I have a worker
I'm trying to make a dictionary game, and I have a text file with
I have just started trying to make a simple game with XNA 3.1 to
I'm trying to make a game in Java (school project) and I have the
I am trying to make a simple game in XNA. I have a player
I am trying to make a screen for a car game and make the
Trying to make a small tapping game, where you have a grid of squares

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.