cocos2d iphone - Collision detection is not working? -


i developing game in cocos2d , working on whole walking through walls part. using accelerometer , here code that:

- (void)update:(cctime)dt {  [self updateofficer]; // [self setplayerposition:_officer.position]; [self setviewpointcenter:self.officer.position]; }  -(void)accelerometer:(uiaccelerometer *)accelerometer didaccelerate:(uiacceleration *)acceleration { //new //constant of 6.0 tilt of device calibration officerspeedy = 6.0 + acceleration.x*10; officerspeedx = -acceleration.y*10; }  -(void)updateofficer { //new [self setplayerposition:_officer.position];  float maxy = 1600 - _officer.contentsize.height/2; float miny = _officer.contentsize.height/2; float newy = _officer.position.y + officerspeedy; newy = min(max(newy, miny), maxy);  float maxx = 1600 - _officer.contentsize.width/2; float minx = _officer.contentsize.width/2; float newx = _officer.position.x + officerspeedx; newx = min(max(newx, minx), maxx);  _officer.position = ccp(newx, newy); cgpoint moveto = _officer.position; [_officer movetoward:moveto]; } 

that works great... think. think following example pretty close , here have.

   -(void)setplayerposition:(cgpoint)position {     cgpoint tilecoord = [self tilecoordforposition:position];     int tilegid = [_meta tilegidat:tilecoord]; if (tilegid) {     nsdictionary *properties = [_tilemap propertiesforgid:tilegid];     if (properties) {         cclog(@"nsdictionary 'properties' contains:\n%@", properties);         nsstring *collision = properties[@"collidable"];         if (collision && [collision isequaltostring:@"true"]) {             nslog(@"coll");             return;         }     }     }     _officer.position = position;     }  - (cgpoint)tilecoordforposition:(cgpoint)position { int x = position.x / _tilemap.tilesize.width; int y = ((_tilemap.mapsize.height * _tilemap.tilesize.height) - position.y) / _tilemap.tilesize.height; return ccp(x, y); } 

so when sprite hits wall runs right through it. in console outputting properties there , true:

2013-05-09 14:21:40.391 10-8[5447:907] nsdictionary 'properties' contains:    {     collidable = true;     } 

any clue why happening?


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -