Thanks for the suggestions. I did end up using the tag method and that works to set the positions of specific tiles when they are released. Now the problem I am having is the touch dispatcher only sets the position of the tiles when you click somewhere other than on the tiles. I want it to be set up so my control class knows all the positions of the tiles and can tell a tile whether or not it can occupy a space. I borrowed the code from the pong test in cocos2d here is what I have.
This part calls the tile:
Texture2D *paddleTexture = [[TextureMgr sharedTextureMgr] addImage:@"sword.png"];
NSMutableArray *paddlesM = [NSMutableArray arrayWithCapacity:10];
equipobject *paddle = [equipobject paddleWithTexture:paddleTexture];
paddle.position = CGPointMake(200, 40);
[paddlesM addObject:paddle ];
for (object *paddle in paddlesM)
[gameMenu addChild:paddle z:8 tag:i];
This is the tile code
#import "equipobject.h"
#import "TouchDispatcher.h"
@implementation equipobject
- (CGRect)rect
{
CGSize s = [self.texture contentSize];
return CGRectMake(-s.width / 2, -s.height / 2, s.width, s.height);
}
+ (id)paddleWithTexture:(Texture2D *)aTexture
{
return [[[self alloc] initWithTexture:aTexture] autorelease];
}
- (id)initWithTexture:(Texture2D *)aTexture
{
if ((self = [super init]) == nil) return nil;
self.texture = aTexture;
return self;
}
- (void)onEnter
{
[[TouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
[super onEnter];
}
- (BOOL)containsTouchLocation:(UITouch *)touch
{
return CGRectContainsPoint(self.rect, [self convertTouchToNodeSpaceAR:touch]);
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
if ( ![self containsTouchLocation:touch] ) return NO;
return YES;
}
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchPoint = [touch locationInView:[touch view]];
touchPoint = [[Director sharedDirector] convertCoordinate:touchPoint];
self.position = CGPointMake(touchPoint.x, touchPoint.y);
}
@end
I can get it to go to a predetermined position by adding in a cctouchended function in the tile object itself but then I can't get it to communicate it's position to other tiles created. If I add it to the control class that calls the tiles it only works when I'm not touching a tile.