码迷,mamicode.com
首页 > 其他好文 > 详细

碰撞的两种实现,

时间:2015-01-13 10:20:44      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

-(void)checkAttack

{

    static BOOL beforeState;

    static int count = 0;

    

    BOOL attack = CGRectIntersectsRect(self.lifeView.frame, self.blockView.frame);

    if (beforeState == 0 && attack == 1) {

        count ++;

        [self.countLabel setText:[NSString stringWithFormat:@"碰撞次数:%d",count]];

    }

    beforeState = attack;

    

    CGFloat blockOriginY = self.lifeView.frame.origin.y - self.blockView.frame.size.height;

    CGFloat maxBlockOriginY = self.lifeView.frame.origin.y + self.blockView.frame.size.height;

    CGFloat lifeOriginX = self.blockView.frame.origin.x - self.lifeView.frame.size.width;

    CGFloat maxLifeOriginX = self.blockView.frame.origin.x + self.lifeView.frame.size.width;

    if ((maxLifeOriginX > self.lifeView.frame.origin.x &&  self.lifeView.frame.origin.x> lifeOriginX) && (self.blockView.frame.origin.y > blockOriginY && maxBlockOriginY > self.blockView.frame.origin.y)) {

        count ++;

        [self.countLabel setText:[NSString stringWithFormat:@"碰撞次数:%d",count]];

        

    }

}

碰撞的两种实现,

标签:

原文地址:http://www.cnblogs.com/guligei/p/4220514.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!