Skip to content

Commit 1ad9331

Browse files
committed
Merge pull request #322 from GuoLunHao/v3
adding comments for create scene without csb file
2 parents 304c93a + ced47c5 commit 1ad9331

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

plugins/plugin_generate/bin-templates/cpp-template-default/Classes/HelloWorldScene.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,59 @@ Scene* HelloWorld::createScene()
2424
// on "init" you need to initialize your instance
2525
bool HelloWorld::init()
2626
{
27+
/** you can create scene with following comment code instead of using csb file.
28+
// 1. super init first
29+
if ( !Layer::init() )
30+
{
31+
return false;
32+
}
33+
34+
Size visibleSize = Director::getInstance()->getVisibleSize();
35+
Vec2 origin = Director::getInstance()->getVisibleOrigin();
36+
37+
/////////////////////////////
38+
// 2. add a menu item with "X" image, which is clicked to quit the program
39+
// you may modify it.
40+
41+
// add a "close" icon to exit the progress. it's an autorelease object
42+
auto closeItem = MenuItemImage::create(
43+
"CloseNormal.png",
44+
"CloseSelected.png",
45+
CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
46+
47+
closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
48+
origin.y + closeItem->getContentSize().height/2));
49+
50+
// create menu, it's an autorelease object
51+
auto menu = Menu::create(closeItem, NULL);
52+
menu->setPosition(Vec2::ZERO);
53+
this->addChild(menu, 1);
54+
55+
/////////////////////////////
56+
// 3. add your codes below...
57+
58+
// add a label shows "Hello World"
59+
// create and initialize a label
60+
61+
auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
62+
63+
// position the label on the center of the screen
64+
label->setPosition(Vec2(origin.x + visibleSize.width/2,
65+
origin.y + visibleSize.height - label->getContentSize().height));
66+
67+
// add the label as a child to this layer
68+
this->addChild(label, 1);
69+
70+
// add "HelloWorld" splash screen"
71+
auto sprite = Sprite::create("HelloWorld.png");
72+
73+
// position the sprite on the center of the screen
74+
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
75+
76+
// add the sprite as a child to this layer
77+
this->addChild(sprite, 0);
78+
**/
79+
2780
//////////////////////////////
2881
// 1. super init first
2982
if ( !Layer::init() )

plugins/plugin_generate/bin-templates/js-template-runtime/src/app.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ var HelloWorldLayer = cc.Layer.extend({
1515
var mainscene = ccs.load(res.MainScene_json);
1616
this.addChild(mainscene.node);
1717

18+
/* you can create scene with following comment code instead of using csb file.
19+
/////////////////////////////
20+
// 3. add your codes below...
21+
// add a label shows "Hello World"
22+
// create and initialize a label
23+
var helloLabel = new cc.LabelTTF("Hello World", "Arial", 38);
24+
// position the label on the center of the screen
25+
helloLabel.x = size.width / 2;
26+
helloLabel.y = size.height / 2 + 200;
27+
// add the label as a child to this layer
28+
this.addChild(helloLabel, 5);
29+
30+
// add "HelloWorld" splash screen"
31+
this.sprite = new cc.Sprite(res.HelloWorld_png);
32+
this.sprite.attr({
33+
x: size.width / 2,
34+
y: size.height / 2
35+
});
36+
this.addChild(this.sprite, 0);
37+
*/
38+
1839
return true;
1940
}
2041
});

plugins/plugin_generate/bin-templates/lua-template-runtime/src/app/views/MainScene.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ MainScene.RESOURCE_FILENAME = "MainScene.csb"
55

66
function MainScene:onCreate()
77
printf("resource node = %s", tostring(self:getResourceNode()))
8+
9+
--[[ you can create scene with following comment code instead of using csb file.
10+
-- add background image
11+
display.newSprite("HelloWorld.png")
12+
:move(display.center)
13+
:addTo(self)
14+
15+
-- add HelloWorld label
16+
cc.Label:createWithSystemFont("Hello World", "Arial", 40)
17+
:move(display.cx, display.cy + 200)
18+
:addTo(self)
19+
]]
820
end
921

1022
return MainScene

0 commit comments

Comments
 (0)