cocos2d 制作5星评分效果

cocos2d 制作5星评分效果,第1张

概述做的是一个评分的展示,不涉及评分的 *** 作 cocos2dx 3.0+ 效果如下,分别为8.6分,5分和10分 五角星图片原图 代码片段 for (int i = 0; i < (int)score / 2; i++) { auto starImg = Sprite::create("appstore/applist/star_full.png"); starImg->setAnchorPo

做的是一个评分的展示,不涉及评分的 *** 作

cocos2dx 3.0+


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



五角星图片原图



代码片段

for (int i = 0; i < (int)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 - (int)score/2;	if ( percent != 0)	{		auto starimg = Sprite::create("appstore/appList/star_empty.png");		starimg->setAnchorPoint(Point::ANCHOR_top_left);		starimg->setposition(26 + (int)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 + (int)score / 2 * 35,48);		starimg2->setTextureRect(Rect(0,starimg2->getContentSize().wIDth * percent,starimg2->getContentSize().height));		_detailHolder->addChild(starimg2,POSTER_LAYER);	}


这边主要是用setTextureRect来切割星星的图片,我也是参考别人学习的这个方法,具体可以看如下链接

http://blog.sina.com.cn/s/blog_65be11bd0101o8ou.HTML

总结

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1016904.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存