Cocos 图片变灰 倒计时进度条

前端之家收集整理的这篇文章主要介绍了Cocos 图片变灰 倒计时进度条前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


cocos2dx 3.8.1版本中

sprite可以实现变色操作

ImageView的只能通过修改底层来变色

GLProgram *program1 = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_GRAYSCALE);
	GLProgram *program2 = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
	
	Sprite* sp = Sprite::create("res/score_bg.png");
	// 下面两种方法 其实是一样的
	sp->setGLProgram(program1);
	//sp->setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
	sp->setPosition(240,200);
	addChild(sp);
	
	ImageView* image = ImageView::create();
	image->setPosition(ccp(240,400));
	image->loadTexture("res/score_bg.png");
	Scale9Sprite*sp9 = (Scale9Sprite*)image->getVirtualRenderer();
	sp9->setState(Scale9Sprite::State::GRAY);
	//sp9->setState(Scale9Sprite::State::NORMAL); 正常状态
	// 下面的方法行不通
	//image->setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_GRAYSCALE));
	addChild(image);
	


	auto sprite = Sprite::create("res/score_bg.png");
	progress = ProgressTimer::create(sprite);
	progress->setPercentage(0);
	progress->setType(ProgressTimer::Type::RADIAL);
	//progress->setReverseDirection(true); 逆时针
	image->addChild(progress);



原文链接:https://www.f2er.com/cocos2dx/340694.html

猜你在找的Cocos2d-x相关文章