开发者

Cocos2D: Referencing a classes TMXLayer from another class

开发者 https://www.devze.com 2023-03-02 19:21 出处:网络
Using Cocos2D. I\'ve currently subclassed much of the player sprite and behaviors away from a debug map, and now I am having trouble referencing a TMXLayer from the sprite class. I\'ve tried allocatin

Using Cocos2D. I've currently subclassed much of the player sprite and behaviors away from a debug map, and now I am having trouble referencing a TMXLayer from the sprite class. I've tried allocating an instance of the DebugZoneLayer class inside this method from the sprite class and releasing it with strange results. This compiles without errors, but fails to test the if (blocksCollidableGID | blocksCollidable2GID){ conditional because debugZoneLayer.blocksCollidable doesn't mean really anything to this method right now.

Method inside sprite class:

-(BOOL) checkTileCollisionForStrafing:(NSString*)omit{

    for(int j = 0; j < _collisPushPointsNums; j++){

        NSValue *val = [_collisPushPoints objectAtIndex:j];
        CGPoint p = [val CGPointValue];

        CGPoint tileCoord;



        if(omit==@"y"){
            tileCoord = [debugZoneLayer tileCoordForPosition:ccp(_heroSprite.position.x+_vel.x+p.x, _heroSprite.position.y+(p.y+.001))];
        }else{
            tileCoord = [debugZoneLayer tileCoordForPosition:ccp(_heroSprite.position.x+p.x, _heroSprite.position.y+_vel.y+p.y)];
        }

        int     blocksCollidableGID  = [debugZoneLayer.blocksCollidable  tileGIDAt:tileCoord];
        int     blocksCollidable2GID = [debugZoneLayer.blocksCollidable2 tileGIDAt:tileCoord];



        if (blocksCollidableGID | blocksCollidable2GID){
            NSLog(@"j = %i", j);
        开发者_如何学JAVA    return YES;
        }
    }

    return NO;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号