hey guys!
I really could use a pair of fresh eyes on this issue.
the thing is that I' m trying to make 41 bricks fall into a grid (6x7) from the top of the screen. everything works fine except for one thing...
...the first row of bricks doesn't fall with the rest of the bricks. it just appears at the allocated location on the grid.
in other words... the row located at 0x0 just appears on the grid while the rest (1x1,2x2 etc) react to CCMoveTo and fall into their allocated location. I'm not sure why row 0x0 doesn't want to "play" with the rest.
I've checked and checked but I still cannot find where the problem is located.
this is how I created the grid and the bricks
gameplaylayer.m
#define GRID_WIDTH 6
#define GRID_HEIGHT 7
#define GRID_OFFSET ccp(168,91)
-(id)init {
//Bricks
CCSpriteBatchNode *SpriteBatchNode;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CCLOG(@"UIUserInterfaceIdiomPad");
[[CCSpriteFrameCache sharedSpriteFrameCache]
addSpriteFramesWithFile:@"bricksiPad1.plist"];
SpriteBatchNode =
[CCSpriteBatchNode batchNodeWithFile:@"bricksiPad1.png"];
} else {
CCLOG(@"UIUserInterfaceIdiomPhone");
[[CCSpriteFrameCache sharedSpriteFrameCache]
addSpriteFramesWithFile:@"bricksiPhone.plist"];
SpriteBatchNode =
[CCSpriteBatchNode batchNodeWithFile:@"bricksiPhone.png"];
}
[self addChild:SpriteBatchNode z:1 tag:kSSheet];
for(int i =0; i< GRID_WIDTH ; i++) {
for(int j =0; j< GRID_HEIGHT ; j++) {
Bricks * b = [[Bricks alloc]initWithGame:self];
grid[i][j] = b;
[b release];
}
}
[self schedule:@selector(placeBricks) interval:0.25];
}
return self;
}
//Place the bricks on the grid
-(void)placeBricks{
CCLOG(@"placeBricks");
[self unschedule:@selector(placeBricks)];
//empty spot in the bottom right corner of the grid
blankPosition = CGPointMake(5, 0);
CCLOG(@"blankPosition Current x %f", blankPosition.x);
CCLOG(@"blankPosition Current y %f", blankPosition.y);
CCLOG(@"-------------------------------------");
[optionsButton setIsEnabled:YES];
for(int i =0; i< GRID_WIDTH ; i++)
{
for(int j =0; j< GRID_HEIGHT ; j++)
{
CGPoint orgPosition = CGPointMake(i,j);
if( blankPosition.x == orgPosition.x && blankPosition.y == orgPosition.y ){
continue;
}
Bricks * leftB = nil;
Bricks *leftmostB= nil;
Bricks * topB= nil;
Bricks *topmostB= nil;
int prohibitedLeft = -1, prohibitedTop = -1;
if(i>=2)
{
leftB = (Bricks *)grid[i-1][j];
leftmostB = (Bricks *)grid[i-2][j];
}
if(j>=2)
{
topB = (Bricks *)grid[i][j-1];
topmostB = (Bricks *)grid[i][j-2];
}
if(leftB && leftmostB && leftB.bricksType == leftmostB.bricksType)
{
prohibitedLeft = leftB.bricksType;
}
if(topB && topmostB && topB.bricksType == topmostB.bricksType)
{
prohibitedTop = topB.bricksType;
}
[grid[i][j] placeInGrid:ccp(100*i + GRID_OFFSET.x,101*j + GRID_OFFSET.y) pt:prohibitedTop pl:prohibitedLeft];
//[self AnimateBricksFallingAtLevelStart]; //I've tried to call the method AnimateBricksFallingAtLevelStart from here as well but still same issue
}
}
[self AnimateBricksFallingAtLevelStart];
}
-(void)AnimateBricksFallingAtLevelStart{
[self unschedule:@selector(AnimateBricksFallingAtLevelStart)];
self.allowTouch = NO;
for(int i =0; i< GRID_WIDTH ; i++)
{
for(int j =0; j< GRID_HEIGHT ; j++)
{
Bricks * d = grid[i][j];
d.mySprite.position = ccp(100*i + GRID_OFFSET.x,2000*j + GRID_OFFSET.y);
CCMoveTo *move = [CCMoveTo actionWithDuration:0.5 position:ccp(100*i + GRID_OFFSET.x,101*j + GRID_OFFSET.y)];
CCDelayTime *delay = [CCDelayTime actionWithDuration:0.2];
//[d.mySprite runAction: move];
CCSequence *Seque = [CCSequence actions: delay, move, nil];
[d.mySprite runAction: Seque];
}
}
}
let me know if I forgot to post any other relevant method
thanks in advance!