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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:29:22+00:00 2026-05-26T13:29:22+00:00

SOLUTION: Simply separating the method call Tile *tile = [[Tile alloc] initWithX:x Y:y]; into

  • 0

SOLUTION:

Simply separating the method call
Tile *tile = [[Tile alloc] initWithX:x Y:y];
into two separate lines such as:
Tile *tile = [Tile alloc];
[tile initWithX:x Y:y];
caused the method to stop receiving the ints as memory pointers. I’m baffled as to why this occurred but it fixed the problems. Any explanations as to why this happened would be appreciated. Thanks to all for the help!

ORIGINAL POST:

This is a bit of a weird question as I’ve run into this problem while doing a tutorial at: http://www.iphonegametutorials.com/2010/09/23/cocos2d-game-tutorial-building-a-slide-image-game/.

The program I have typed out works except for the switching of tiles, and I have looked in the XCode debugger and it seems that my x and y values for the Tile class are being set way to absurdly high values. The weird thing is, when the values are passed to the method (initWithX:Y:) from the original method (initWithSize:imgSize:) they are what they should be, but when they arrive at the method they are huge (for example: in one instance an x passed as ‘1’ becomes ‘1065353216’ when it arrives at the method.)

I have a feeling that it may be pointing to the memory location of the passed int, but I don’t see any reason why it should be in my code. See below.

-(id)initWithSize:(CGSize)aSize imgSize:(int)aImgValue {
self = [super init];
imgValue = aImgValue;
size = aSize;
OutBorderTile = [[Tile alloc] initWithX:-1 Y:-1];
content = [NSMutableArray arrayWithCapacity:size.height];

readyToRemoveTiles = [NSMutableSet setWithCapacity:50];

for(int y = 0; y < size.height; y++) {
    NSMutableArray *rowContent = [NSMutableArray arrayWithCapacity:size.width];
    for (int x = 0; x < size.width; x++) {
        Tile *tile = [[Tile alloc] initWithX:x Y:y];
        [rowContent addObject:tile];
        [readyToRemoveTiles addObject:tile];
        [tile release];
    }
    [content addObject:rowContent];
    [content retain];
}
[readyToRemoveTiles retain];
return self;
}

-(id)initWithX:(int)posX Y:(int)posY {
self = [super init];
x = posX;
y = posY;
return self;
}

Everything should be the same as in the linked tutorial, but I can’t see anybody else complaining of the same problem.

I have also noted that if I go into the debugger and manually change the posX and posY values in the initWithX method that the tile switching code works, so my problem definitely lies with the really large int values forming in that method.

Edit for Jim: Hopefully this shows a more complete picture of the layout I have for the Tile object.

@interface Tile : NSObject {
int x, y, value;
CCSprite *sprite;
}

@property(nonatomic, readonly) int x, y;
@property(nonatomic) int value;
@property(nonatomic, retain) CCSprite *sprite;

@end

@implementation Tile

@synthesize x, y, value, sprite;

// Code is logged in below. 
-(id)initWithX:(int)posX Y:(int)posY {
self = [super init];
x = posX;
y = posY;
return self;
}

@end
  • 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-26T13:29:23+00:00Added an answer on May 26, 2026 at 1:29 pm

    Somewhere, the x and/or y value are being assigned to a pointer. One thing I would check is to make sure you aren’t declaring your ints as pointers to ints. I.e. int *x, etc.

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

Sidebar

Related Questions

Here is what I'm looking for: I'd like to separate pieces of functionality into
I'm discovering a simple solution for singular-plural keywords searches. I heard about stemming but
I'm looking for a simple solution using Python to store data as a flat
I am looking for a simple solution to do Exception Logging combined with Error
There might be a really simple solution to this question, but i just don't
Probably a long question for a simple solution, but here goes... I have a
I'm trying to find a simple solution to a specific problem, which is a
I feel like there's a simple solution to this, but I'm not really sure
Im pretty sure this has a simple solution. I am using jCarousellite, and i
Im sure there is a very simple solution for this. I have a bunch

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.