我自己的爪机是 480*854 的分辨率的,但是……笔记本也就 768 的高度。
于是:
eglView->setViewName("2048"); eglView->setFrameSize(240, 427);
AppDelegate.cpp 就是Cocos2d的入口了。
pDirector->setDisplayStats(false);
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480,854,kResolutionShowAll);
MyScene.h 我加上了这几个:
void menuCall_start(CCObject *pSender); //开始动作 void menuCall_thend(CCObject *pSender); //退出动作 CCSize size ; // 屏幕大小
MyScene.cpp 全部内容:
#include "MyScene.h" #include "2048Scene.h" // 开始游戏需要进入 MyScene::MyScene(void) { } MyScene::~MyScene(void) { } CCScene* MyScene::scene() { // 'scene' is an autorelease object CCScene *scene = CCScene::create(); // 'layer' is an autorelease object MyScene *layer = MyScene::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene; } bool MyScene::init() { //CCSize size =CCDirector::sharedDirector()->getWinSize(); // 获取屏幕大小 //size=CCDirector::sharedDirector()->getWinSize(); size.width=480,size.height=854;//手动设定 CCSprite *homepage=CCSprite::create("homepage.png"); homepage->setPosition(ccp(size.width/2,size.height*0.5)); this->addChild(homepage); //CCSprite *bg=CCSprite ::create("HelloWorld.png"); //bg->setPosition(ccp(size.width/2,size.height/2)); //ccp=CCPoint //this->addChild(bg); /*CCSprite *sp0=CCSprite::create("icon.png"); sp0->setPosition(ccp(100,100)); this->addChild(sp0);*/ /* CCSprite *sp1=CCSprite::create("CloseNormal.png"); sp1->setPosition(ccp(100,100)); bg->addChild(sp1);*/ /* CCSprite *sp1=CCSprite::create("icon.png"); sp1->setPosition(ccp(size.width*0.2,size.height*0.7)); this->addChild(sp1); CCSprite *sp2=CCSprite::create("icon.png",CCRect(28,28,29,29));//坐标,长,宽 sp2->setPosition(ccp(size.width*0.4,size.height*0.7)); this->addChild(sp2); CCTexture2D *Texture=CCTextureCache::sharedTextureCache()->addImage("icon.png"); // 创建2D纹理 CCSprite *sp3=CCSprite::createWithTexture(Texture); sp3->setPosition(ccp(size.width*0.6,size.height*0.7)); this->addChild(sp3); CCSprite *sp4=CCSprite::createWithTexture(Texture,CCRect(0,0,40,40)); sp4->setPosition(ccp(size.width*0.8,size.height*0.7)); this->addChild(sp4); CCSpriteFrame *frame=CCSpriteFrame::create("icon.png",CCRect(0,0,57,57)); // 缓存帧 CCSprite *sp5=CCSprite::createWithSpriteFrame(frame); sp5->setPosition(ccp(size.width*0.3,size.height*0.3)); this->addChild(sp5); //sp5->setScale(2); //放大两倍 //sp5->setScale(0.5); //缩小一半 //sp5->setRotation(30); //顺时针旋转30度 //sp5->setRotation(-30); //逆时针旋转30度 //sp5->setSkewX(30); //水平顺时针倾斜30度 //sp5->setSkewX(-30); //水平逆时针倾斜30度 //sp5->setVisible(false); //是否可见 //sp5->setColor(ccc3(255,0,0)); //设置颜色 //sp5->setOpacity(30); //透明度 透明0-255不透明 //sp5->setTexture(CCTextureCache::sharedTextureCache()->addImage("CloseNormal.png")); //更改显示的图片 // 还有一种缓存帧的方式,使用img.plist */ /*CCLabelTTF *laber1 =CCLabelTTF :: create("fuck" ,"consola",25); laber1->setPosition(ccp(size.width/2,size.height*0.7)); laber1->setColor(ccc3(255,255,0)); this->addChild(laber1);*/ //文字 /*CCLabelTTF *laber1 =CCLabelTTF :: create("start" ,"consola",50); CCMenuItemLabel *item1 =CCMenuItemLabel::create(laber1,this,menu_selector(MyScene::menuCall_start)); item1->setPosition(ccp(size.width/2,size.height*0.7)); */ CCMenuItemImage *item_start=CCMenuItemImage :: create("start-normal.png","start-select.png",this,menu_selector(MyScene::menuCall_start)); item_start->setPosition(ccp(size.width/2,size.height*0.5)); CCMenuItemImage *item_thend=CCMenuItemImage :: create("thend-normal.png","thend-select.png",this,menu_selector(MyScene::menuCall_thend)); item_thend->setPosition(ccp(size.width/2,size.height*0.3)); CCMenu *menu =CCMenu::create(item_start,item_thend,NULL); menu->setPosition(CCPointZero); this->addChild(menu); CCLabelTTF *My=CCLabelTTF::create("dongshimou@gmail.com","fonts/FZNHT.TTF",40); My->setPosition(ccp(size.width/2,size.height/10)); this->addChild(My); return true; } void MyScene::menuCall_start(CCObject *pSender) { //system("pause"); CCScene *temps=My2048Scene::scene(); CCDirector::sharedDirector()->replaceScene(temps); } void MyScene::menuCall_thend(CCObject *pSender) { //system("pause"); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert"); #else CCDirector::sharedDirector()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif #endif }
由于2048Scene 还没写,注释掉 #include "2048Scene.h"
还有 menuCall_start 函数里面的内容。
还有五张图片,一个字体。
homepage.png,start-normal.png,start-select.png,thend-normal.png,thend-select.png,FZNHT.TTF
效果图
背景图 是 480*854 其它四个是250*150 的 , 分别是选中前和选中后的不同。字体效果如图。
百度云:http://pan.baidu.com/s/1sjmDyhf
原文地址:http://blog.csdn.net/dongshimou/article/details/39547833