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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:30:31+00:00 2026-05-29T12:30:31+00:00

im new to programming, i have been experimenting with cocos2d, heres the problem, i

  • 0

im new to programming, i have been experimenting with cocos2d, heres the problem, i have made a simple game, device in portrait, it has falling sprites, and i want the sprite to disappear when the position of the top of the sprite < screen.height/2 how can this be done?

heres some code you may be interested in:

this is the falling sprite, it falls from the top of the screen to the bottom

-(void)addRock {

CCSprite *rock = [CCSprite spriteWithFile:@"rock.png" 
                                     rect:CGRectMake(0, 0, 27, 40)]; 

// Determine where to spawn the target along the X axis
CGSize winSize = [[CCDirector sharedDirector] winSize];
int minX = rock.contentSize.width/2;
int maxX = winSize.width - rock.contentSize.width/2;
int rangeX = maxX - minX;
int actualX = (arc4random() % rangeX) + minX;

// Create the target slightly off-screen along the right edge,
// and along a random position along the X axis as calculated above
rock.position = ccp(actualX, 500);
[self addChild:rock];

// Determine speed of the target
int actualDuration = spriteDuration;//speed of sprite

// Create the actions
id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(actualX,-winSize.height+ rock.contentSize.height)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
[rock runAction:[CCSequence actions:actionMove, nil]];

}

when the sprite move has finished

-(void)spriteMoveFinished:(id)sender {
CCSprite *sprite = (CCSprite *)sender;
[self removeChild:sprite cleanup:YES];

}

  • 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-05-29T12:30:32+00:00Added an answer on May 29, 2026 at 12:30 pm

    To fade your sprite out halfway of the Animation you can use CCSpawn to combine the falling animation with the fadeOut. But as you want it to fade out after a given time, you need to create a Sequence of CCDelayTime and CCFadeOut.

    double fadeStart = 0.5;
    id wait    = [CCDelayTime actionWithDuration: actualDuration * fadeStart];
    id fadeOut = [CCFadeOut actionWithDuration: actualDuration * (1.0 - fadeStart)];
    id waitThenFade = [CCSequence actions: wait, fadeOut, nil];
    
    id actionMove = ...;
    id fullAnimation = [CCSpawn actions:actionMove, waitThenFade, nil];
    
    [rock runAction:[CCSequence actions:fullAnimation, actionMoveDone, nil]];
    

    In case you want the fading to start earlier or later you simply have to move the fadeStart value. 0 will start immediately, 1 will actually not fade, so better pick a value in between.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to web programming...I have been asked to create a simple Internet
I'm very much new to programming and have been doing fairly well so far.
I am new to programming. I have been trying to write a function in
I have been working on Eclipse recently. I am fairly new to java programming,
I'm fairly new to database programming in WinForms, and have been using BindingSource, DataSet,
I'll admit, I am pretty new with ASP .NET programming and I have been
I am pretty new to programming(just finished University). I have been thought in the
Hi there I am new to C programming and have been using Xcode to
I am very new to programming, and have been banging my head against the
I'm new to Python (I have been programming in Java for multiple years now

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.