iphone - detect collision with sprite in sprite sheet -


i have sprite sheet in there 4 images(bat1,bat2,bat3.bat4) , in image there person holding bat , when images combined in animation looks playing baseball. below code have used add sprite sheet.

[[ccspriteframecache sharedspriteframecache] addspriteframeswithfile:@"baseball.plist"];  spritesheet = [ccspritebatchnode batchnodewithfile:@"baseball.plist"]; [self addchild:spritesheet];  background = [ccsprite spritewithspriteframename:@"bat4.png"]; background.position = ccp(220, 185); background.tag = 10; [self addchild:background];  for(int = 1; < 5; i++) {         [walkanimframes addobject:[[ccspriteframecache sharedspriteframecache]    spriteframebyname:[nsstring stringwithformat:@"bat%d.png", i]]]; } 

ccanimation *walkanim = [ccanimation animationwithspriteframes:walkanimframes delay:5.0f];

 self.walkaction = [ccrepeatforever actionwithaction:[ccanimate actionwithanimation:walkanim]];  [background runaction:_walkaction]; 

and detecting collision of ball bat. below code

for (ccsprite *monster in _monsters) {         if (cgrectintersectsrect(background.boundingbox, monster.boundingbox)) {             if (((background.position.x -5 > monster.position.x + (monster.contentsize.width/2)) && background.position.y > monster.position.y)) {                 iscollision = 1;                 [monsterstodelete addobject:monster];             }            // [monsterstodelete addobject:monster];             //[self addfishtoboat];         }     } 

here wat happen collision detected detect collision rect of bat4.. bat moving , cgrect of bat different when bas far away bat1 detect collision because ball's rect intersect rect of bat4.

but want collision de detect when ball collide wiith different bats, mean when bal hit bat1,bat2,bat3,bat4 detect collision rather detect bat4 always

here great tutorials raywenderlich on sprites collision detection.

or

you can try tutorial sprite collision

hope these you.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -