Cocos2d-x   发布时间:2022-05-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了cocos2d 制作5星评分效果大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_489_0@做的是一个评分的展示,不涉及评分的操作

@H_489_0@cocos2dx 3.0+

@H_489_0@

@H_489_0@效果如下,分别为8.6分,5分和10分

@H_489_0@

@H_489_0@

@H_489_0@五角星图片原图

@H_489_0@

@H_489_0@

@H_489_0@代码片段

for (int i = 0; i < (@R_262_10185@score / 2; i++)
	{
		auto starImg = Sprite::create("appstore/applist/star_full.png");
		starImg->setAnchorPoint(Point::ANCHOR_TOP_LEFT);
		starImg->setPosition(26 + i * 35,48);
		_detailHolder->addChild(starImg,POSTER_LAYER);
	}
	float percent = score/2 - (@R_262_10185@score/2;
	if ( percent != 0)
	{
		auto starImg = Sprite::create("appstore/applist/star_empty.png");
		starImg->setAnchorPoint(Point::ANCHOR_TOP_LEFT);
		starImg->setPosition(26 + (@R_262_10185@score / 2 * 35 + starImg->getContentSize().width * percent,48);
		starImg->setTextureRect(Rect(starImg->getContentSize().width * percent,starImg->getContentSize().width - starImg->getContentSize().width * percent,starImg->getContentSize().height));
		_detailHolder->addChild(starImg,POSTER_LAYER);

		auto starImg2 = Sprite::create("appstore/applist/star_full.png");
		starImg2->setAnchorPoint(Point::ANCHOR_TOP_LEFT);
		starImg2->setPosition(26 + (@R_262_10185@score / 2 * 35,48);
		starImg2->setTextureRect(Rect(0,starImg2->getContentSize().width * percent,starImg2->getContentSize().height));
		_detailHolder->addChild(starImg2,POSTER_LAYER);
	}
@H_489_0@

这边主要是用setTextureRect来切割星星的图片,我也是参别人学习的这个方法,具体可以看如下链接 @H_489_0@http://blog.sina.com.cn/s/blog_65be11bd0101o8ou.html

大佬总结

以上是大佬教程为你收集整理的cocos2d 制作5星评分效果全部内容,希望文章能够帮你解决cocos2d 制作5星评分效果所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。