开发者

display part of an image and hide the rest using CCScene

开发者 https://www.devze.com 2023-04-11 19:26 出处:网络
ok so i have the following code : CCScene * timerLayer = [CCScene node]; [timerLayer setContentSize:CGSizeMake(50, 36)];

ok so i have the following code :

CCScene * timerLayer = [CCScene node];
[timerLayer setContentSize:CGSizeMake(50, 36)];
timerLayer.position = ccp(100, 260);
if(![self getChildByTag:777]){
    [self addChild:timerLayer z:20 tag:777];
}


timerGraphic = [CCSprite spriteWithFile:@"timer_small.png"];
timerGraphic.position = ccp(0,0);
timerLayer.contentSize = CGSizeMake(50, 36);

if(![timerLayer getChildByTag:779]){
    [timerLayer addChild:timerGraphic z:19 tag:779];
}

as you can see, I am making a timerLayer Scene, and I have resized the the scene to 50x, 36y. and I also have timerGraphic, and I just want to show 50x 36y of this sprite so i tried resizing the scen开发者_如何学运维e, but its not working... its showing the entire image all together!


The CCScene node can not be used to clip images. You can either use a Clipping Node or in your case simply change the texture rect to only display that part of the image that's inside the rectangle:

[timerGraphic setTextureRect:CGRectMake(0, 0, 50, 36)];

Note: be sure that the rect is within the image's bounds!

0

精彩评论

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

关注公众号