Find Jobs
Hire Freelancers

Cocos2d Collision Bug

$10-30 USD

Preklicano
Objavljeno pred približno 10 leti

$10-30 USD

Plačilo ob dostavi
After continuously debugging and trying to fix this problem I am still have absolutely no luck…Can anyone please help me with this? It’s driving me insane.. I am using cocos2d v2 for iOS and basically I made a simple collision detection check method: -(bool)collisionWithPoint:(CGPoint)center1 andRadius:(float)radius1 andPoint:(CGPoint)center2 andRadius:(float)radius2 { float a = center2.x - center1.x; float b = center2.y - center1.y; float c = radius1 + radius2; float distanceSquared = (a * a) + (b * b); if (distanceSquared < (c * c)) { return YES; } else { return NO; } } I also have an array keeping track of my enemies being added to the scene. I alloc in the init method: _enemyFish = [[NSMutableArray alloc]init]; Then I add my enemy to the array like this: [self addChild:yellowFish z:50]; [_enemyFish addObject:yellowFish]; I also remove it from the array like this: CCMoveTo *move = [CCMoveTo actionWithDuration:speed position:ccp([login to view URL], randY)]; CCCallBlockN *done = [CCCallBlockN actionWithBlock:^(CCNode *node){ [_enemyFish removeObject:node]; [node removeFromParentAndCleanup:YES];}]; [blueFish runAction:[CCSequence actions:move,done, nil]]; Then in my update method I check for collisions: -(void)update:(ccTime)dt { for (CCSprite *enemy in _enemyFish) { if ([self collisionWithPoint:[login to view URL] andRadius:[login to view URL] * .3 andPoint:[login to view URL] andRadius:[login to view URL] * .4]) { [self gameOver]; } } } However, my issue is that my player will randomly die (gameOver scene being called) without being anywhere near the enemy. This only happens randomly though which confuses me. I have debugged with multiple CCLog statements to determine that this is indeed the issue. Does anyone have any idea why I would randomly be “colliding” with nothing based off of my given code? I can provide other code if needed. Thank you!
ID projekta: 5754482

Več o projektu

Projekt na daljavo
Aktivno pred 10 leti

Želite zaslužiti?

Prednosti oddajanja ponudb na Freelancerju

Nastavite svoj proračun in časovni okvir
Prejmite plačilo za svoje delo
Povzetek predloga
Registracija in oddajanje ponudb sta brezplačna

O stranki

Zastava UNITED STATES
Lakewood, United States
5,0
11
Plačilna metoda je verificirana
Član(ica) od avg. 25, 2013

Verifikacija stranke

Hvala! Po e-pošti smo vam poslali povezavo za prevzem brezplačnega dobropisa.
Pri pošiljanju vašega e-sporočila je šlo nekaj narobe. Poskusite znova.
Registrirani uporabniki Skupaj objavljenih del
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Nalaganje predogleda
Geolociranje je bilo dovoljeno.
Vaša prijavna seja je potekla, zato ste bili odjavljeni. Prosimo, da se znova prijavite.