ccpClamp在Cocos2d中做了什么?

GPP*_*GPP 2 objective-c cocos2d-iphone

谷歌什么都没产生,所以我想问问.ccp实现了什么?

以下是在方法中使用ccpClamp的示例.

-(void) moveCamera:(CGPoint)pos
    {
        CGPoint to = ccpClamp(pos, cameraMin, cameraMax);
        to = ccpSub(to, cameraOffset);
        [self.camera setCenterX:to.x centerY:to.y centerZ:0];
        [self.camera setEyeX:to.x eyeY:to.y eyeZ:[CCCamera getZEye]];

        // update hud-level sprites
        [(HudLayer*)[self.parent getChildByTag:kTagHudLayer] moveSprites:[self getCameraPosition]];
    }
Run Code Online (Sandbox Code Playgroud)

jwe*_*ich 5

官方文档并没有解释这个词是什么手段,但它是用来值限制为一组边界(低,高).在您的示例中,它相当于:

if (pos < cameraMin)
    return cameraMin;
else if (pos > cameraMax)
    return cameraMax;
else
    return pos;
Run Code Online (Sandbox Code Playgroud)

dictionary.com,clamp表示:

  1. 通常由一些刚性材料制成的装置,用于加强或支撑物体或将它们紧固在一起.
  2. 具有相对侧面或部件的器具,可以调节或靠近在一起以保持或压缩某物.