我需要设置按钮的精灵框架。
当我使用构造函数时它正在工作:
CCSprite *sprite = [CCSprite spriteWithImageNamed:@"but.png"];
CCButton *button = [CCButton buttonWithTitle:@"" spriteFrame:sprite.spriteFrame];
[button setBlock:^(id sender){...}]
但是当我之后需要设置精灵框架时,
CCButton *button = [CCButton buttonWithTitle:@""];
button.background.spriteFrame = sprite.spriteFrame;
or this
[button setBackgroundSpriteFrame:sprite.spriteFrame forState:CCControlStateNormal];
两者都不起作用,结果是图像扭曲,并且不会调用回调函数或块。
您好,我遇到了同样的问题并找到了解决方案。只需这样做:
CCSpriteFrame *spriteFrame = [CCSpriteFrame frameWithImageNamed:@"Icon-Small.png"];
button = [CCButton buttonWithTitle:@"" spriteFrame:spriteFrame];
奇迹般有效!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)