cocos2d iphone - Adding CCSprite on Tiled tile properties -
i'm trying add sprite beside player, when tile beside player not wall. know tiled tiles working properly, job in method:
cgpoint p = cgpointmake(tilecoord.x, tilecoord.y - 1); if ([self isvalidtilecoord:p] && ![self iswallattilecoord:p]) { [tmp addobject:[nsvalue valuewithcgpoint:p]]; t = yes; i checking tiled on coordinate these 2 methods:
-(bool)isprop:(nsstring*)prop attilecoord:(cgpoint)tilecoord forlayer:(cctmxlayer *)layer { if (![self isvalidtilecoord:tilecoord]) return no; int gid = [layer tilegidat:tilecoord]; nsdictionary * properties = [_tilemap propertiesforgid:gid]; if (properties == nil) return no; return [properties objectforkey:prop] != nil; } -(bool)iswallattilecoord:(cgpoint)tilecoord { return [self isprop:@"wall" attilecoord:tilecoord forlayer:_bglayer]; } (thanks raywenderlich)
and code adding sprite
cgpoint tilecoord = ccp(_player.position.x - 24 +60, player.position.y); cgpoint ctilecoord = [self tilecoordforposition:tilecoord]; nslog(@" t: %@, c: %@", cgpointcreatedictionaryrepresentation(tilecoord), cgpointcreatedictionaryrepresentation(ctilecoord) ); if (![self iswallattilecoord:ctilecoord]) { nslog(@"false"); circle1.position = ccp(_player.position.x - 24 +60, _player.position.y); [self addchild:circle1]; } else { nslog(@"true"); } what want add circle1 sprite left of player when there isn't wall tile there. problem code detects false, no matter if there wall there or not. of guys understand why not detect walls , how can fix it?
you should check if tile map has correct layer settings. did mistake once, easy forget
Comments
Post a Comment