cocos new MyGame -p com.example.mygame -l cpp -d ./MyGame
cpp
#include "HelloWorldScene.h"
USING_NS_CC;
Scene* HelloWorld::createScene()
{
auto scene = Scene::create();
auto layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init()
{
if (!Layer::init())
{
return false;
}
auto director = Director::getInstance();
auto visibleSize = director->getVisibleSize();
auto origin = director->getVisibleOrigin();
auto label = Label::createWithTTF("Hello, Cocos2d!", "fonts/Marker Felt.ttf", 24);
label->setPosition(Vec2(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height - label->getContentSize().height));
this->addChild(label);
return true;
}
cpp
bool AppDelegate::applicationDidFinishLaunching()
{
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if (!glview)
{
glview = GLViewImpl::create("My Game");
director->setOpenGLView(glview);
}
director->setDisplayStats(true);
director->setAnimationInterval(1.0 / 60);
auto scene = HelloWorld::createScene();
director->runWithScene(scene);
return true;
}
cocos compile -p win32 (Windows)
cocos compile -p mac (Mac)
cocos run -p win32 (Windows)
cocos run -p mac (Mac)