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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:42:56+00:00 2026-05-19T16:42:56+00:00

I need to make an array for the co ordinates of my sprites and

  • 0

I need to make an array for the co ordinates of my sprites and i wanted to remove the co-ordinate once the sprite has that co-ordinate from the array as i don’t want another sprite having the same co-ordinate, i can’t seem to get it to work, there are no errors and when debugging it says nsexception and quits. what am i doing wrong and where do i deallocate the arrays? when i release them in dealloc it says i need to declare them.

CGPoint cg1 = CGPointMake(33,33);
NSValue *cg1obj = [NSValue valueWithCGPoint:cg1];

CGPoint cg2 = CGPointMake(33,97);
NSValue *cg2obj = [NSValue valueWithCGPoint:cg2];

NSMutableArray *numberxy = [[NSMutableArray alloc] init]; int pointcount = 0;
[numberxy insertObject:cg1obj atIndex:pointcount++];
[numberxy insertObject:cg2obj atIndex:pointcount++];

NSMutableArray  *sprites = [[NSMutableArray alloc] init]; int spritecount = 0;
[sprites insertObject:red1 atIndex:spritecount++];
[sprites insertObject:red2 atIndex:spritecount++];

for (int i=0; i<3;i++) {
    int rpoint = arc4random() % 3;
    int rsprite = arc4random() % 3;

    CGPoint point = [[numberxy objectAtIndex:rpoint] CGPointValue];

    CCSprite *sprite1 = [sprites objectAtIndex:rsprite];

    sprite1.position = ccp(point.x,point.y);

    if (sprite1.position.x == point.x && sprite1.position.y == point.y) {
        [numberxy removeObjectAtIndex:rpoint];
        [sprites removeObjectAtIndex:rsprite];
    }
}
  • 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-19T16:42:57+00:00Added an answer on May 19, 2026 at 4:42 pm

    Your code is weird. Why is xValue defined after it is used? You may have a leak if xValue was defined previously in the same manner and now you are redefining xValue. You then check if X is in the new xValue. There is nothing in the new xValue so the if statement will evaluate to false, so nothing will be removed.

    NSNumber *X = [NSNumber numberWithInt:randomNumberx];
    [xValue containsObject: numberx];
    
    xValue = [[NSMutableArray alloc]init];
    if ([xValue containsObject:X]) {
        [numberx removeObject:X];
    }
    

    Also what is the point of [xValue containsObject: numberx]; outside of the if statement? It doesn’t have a purpose.

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

Sidebar

Related Questions

I need to make array from class name that have no class name 'hidden':
I need to make new array of string elements, from elements in one default
what is wrong with this code: I need to make one array from lines
I need to make a key name from a array a reference to a
I need to make an array in php that will output an html table
I need to make a Javascript object that would behave as an associative array,
Hi I need to make an dynamic array like this: I have a max
For executing array methods on NodeList objects(Array like) we need to make indirect call
I need make a merge sort using an additional array. Here is my code:
I have two arrays in php and I need to make a new array

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.