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

  • Home
  • SEARCH
  • 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 7172965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:43:30+00:00 2026-05-28T15:43:30+00:00

I am using the tutorial to make one simple app. And unlike the sample

  • 0

I am using the tutorial to make one simple app. And unlike the sample app, I want to show my projectile/object from the very beginning instead of on touch. For the same, I am doing like this :

-(id) init
{
    if((self=[super init]))
    {
        [[SimpleAudioEngine sharedEngine]setEnabled:TRUE];
        winSize = [CCDirector sharedDirector].winSize;
        projectile = [CCSprite spriteWithFile:@"abc.png"];
        projectile.position = spriteOffset;
        self addChild:projectile];
        self.isTouchEnabled = YES;
        //some other code
   }
}

And then on touch of the same object/projectile, I need to move it to the direction i have moved it to. I am doing the below for the same :

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Choose one of the touches to work with
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    // Determine offset of location to projectile
    int offX = location.x - projectile.position.x; //Projectile returns 0X0 here
    int offY = location.y - projectile.position.y;

    float scalarX = 1.0f;

    if (offX < 0.0f)
        scalarX = -1.0f;

    int realX = scalarX * (winSize.width + (projectile.contentSize.width/2));//winSize.width + (food.contentSize.width/2);
    float ratio = (float) offY / (float) offX;
    int realY = (realX * ratio) + projectile.position.y;
    CGPoint realDest = ccp(realX, realY);

    int offRealX = realX - projectile.position.x;
    int offRealY = realY - projectile.position.y;
    float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY));
    float velocity = 480/1; // 480pixels/1sec
    float realMoveDuration = length/velocity;

    [projectile runAction:[CCSequence actions:
                       [CCMoveTo actionWithDuration:realMoveDuration position:realDest],
                       [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)],
                       nil]];
    [_projectiles addObject:projectile];  //ERROR SIGABRT

}

In the above code, at this line int offX = location.x - projectile.position.x; my sprite returns into 0X0. I am not getting where i am making mistake. At the first, it shows the objects on the screen but on touch event, it gets disappeared. I also have synthesized the CCSprite but in vail. Is there any other way around or any mistake that I am performing? Please help if any idea. Thank you.

ERROR : Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'
  • 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-28T15:43:31+00:00Added an answer on May 28, 2026 at 3:43 pm

    Actually, since the projectile sprite is added as child in init, the only way it will be autoreleased is if elsewhere in the code the projectile is removed as child. You have to find where that is happening. Just forcing it to be ‘sticky’ with a retain may corrupt the logic about the sprite removal reason(s).

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

Sidebar

Related Questions

All, I am (trying to) using Netbeans to build a simple Qt app (from
I am trying to parse JSON in an Adobe Flex app, using http://www.mikechambers.com/blog/2006/03/28/tutorial-using-json-with-flex-2-and-actionscript-3/'>This Tutorial
I am trying to make a simple menu with a nice transition effect using
I want to make an installing application using vb.net(not asp.net) where i can login
I try to follow the facebook-android tutorial from here: https://developers.facebook.com/docs/mobile/android/build/#sample I am working in
I'd like to make a video tutorial for my SDK--one of those videos that
I downloaded Ray Wenderlich's simple contact listener from this tutorial: http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone Currently I am
I'm developing a Cocoa app using XCode 4. One of the windows has a
So I'm trying to just add a simple ad to my app using admob.
I am using this tutorial to create a login form http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/ It authenticates against

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.