I have functions that successfully find the CGRect for a sprite, return it and use it in a CGRectIntersectsRect(rect1,rect2) function.
I copied and modified the function to accept (AtlasSprite *) instead of (Sprite *) and it never seems to find the x and y position of the AtlasSprite. In the function that starts the Animation on the AtlasSprite, it setPositions of the AtlasSprite no problem.
- (void)collisionWithPowerUp: (AtlasSprite *) powerUp {
Sprite *ship = (Sprite *)[self getChildByTag:1];
NSLog(@"ShipXY=(%f,%3f) PowerXY=(%f,%f)",ship.position.x,ship.position.y,powerUp.position.x,powerUp.position.y);
CGRect shipBounds = [self makeRect:ship];
CGRect powerBounds = [self makeRectA:powerUp];
if(CGRectIntersectsRect(powerBounds, shipBounds)){
[[SimpleAudioEngine sharedEngine] playEffect:@"powerup.wav"]; //PowerUp Sound
[self removePowerUp:powerUp];
ammo = ammo + 20;
[self updateAmmo];
}
}
Here is makeRectA:
- (CGRect)makeRectA:(AtlasSprite *)mySprite
{
// ** Wasnt working either ** return CGRectMake(mySprite.position.x - (mySprite.contentSize.width*mySprite.scale) /2, mySprite.position.y - (mySprite.contentSize.height*mySprite.scale) / 2, (mySprite.contentSize.width*mySprite.scale), (mySprite.contentSize.height*mySprite.scale));
CGSize contentSize = [mySprite contentSize];
CGPoint contentPosition = [mySprite position];
NSLog(@"PowerUp Position(X,Y) = (%f,%f)",mySprite.position.x, mySprite.position.y);
CGRect result = CGRectOffset(CGRectMake(0, 0, contentSize.width, contentSize.height), contentPosition.x-contentSize.width/2, contentPosition.y-contentSize.height/2);
return result;
}
Its being called from step: with
AtlasSpriteManager *powerUpMgr = (AtlasSpriteManager*) [self getChildByTag:201];
AtlasSprite *powerUp = [AtlasSprite spriteWithRect:CGRectMake(0, 0, 64, 768) spriteManager: powerUpMgr];
[self collisionWithPowerUp:powerUp];
I'm trying to supply all the code that I think has any meaning.
In every case where I am trapping x and y of the atlasSprite, they are returning 0. The ship is just a sprite and returns its current x and y correctly.