作者:黑天天 | 来源:互联网 | 2023-08-06 12:36
之前在3.0上可以正常在win32上显示,真是好不容易,什么坐标偏移之类的都花了不少时间到网上去找资料,可是因为项目问题,换了3.2,结果崩溃了。下面先贴上在3.2下win32的解决办法。
之前在3.0上可以 正常在win32上显示,真是好不容易,什么坐标偏移之类的都花了不少时间到网上去找资料,可是因为项目问题,换了3.2,结果崩溃了。下面先贴上在3.2下win32的解决办法。
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2));
// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
auto label = LabelTTF::create("Hello World", "Arial", 24);
// position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, 1);
// add "HelloWorld" splash screen"
auto sprite = Sprite::create("HelloWorld.png");
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite,0);
graySprite(sprite);
auto button = Button::create("HelloWorld.png");
button->setPosition(Vec2(visibleSize.width/4 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(button);
//button->getVirtualRenderer()
graySprite(static_cast(button->getVirtualRenderer()));
return true;
}
void HelloWorld::graySprite(cocos2d::Sprite * sprite)
{
if(sprite)
{
GLProgram * p = new GLProgram();
p->initWithFilenames("gray.vsh", "gray.fsh");
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
p->link();
p->updateUniforms();
sprite->setShaderProgram(p);
}
}
效果图:
迟点再贴Lua的代码,包括变灰以及还原。
两个文件,差点忘了。
http://download.csdn.net/detail/u011922261/7983373