学习笔记
来源:互联网 发布:autodesk主要软件 编辑:程序博客网 时间:2024/05/29 15:43
获取屏幕大小(Visible)
1.
<code
class
=
"perl"
>Size visibleSize = Director::getInstance()->getVisibleSize();
2.
Vec2 origin = Director::getInstance()->getVisibleOrigin();
3.
</code>
打印调试(CCLOG)
1.
<code
class
=
"perl"
><code
class
=
"perl"
>CCLOG(
"Characters: %c %c"
,
'a'
,
65
);
2.
CCLOG(
"Decimals: %d %ld"
,
1977
, 650000L);
3.
CCLOG(
"Preceding with blanks: %10d"
,
1977
);
4.
CCLOG(
"Preceding with zeros: %010d"
,
1977
);
5.
CCLOG(
"Some different radixes: %d %x %o %#x %#o"
,
100
,
100
,
100
,
100
,
100
);
6.
CCLOG(
"Floats: %4.2f %.0e %E"
,
3.1416
,
3.1416
,
3.1416
);
7.
CCLOG(
"%s"
,
"A string"
);
8.
</code></code>
创建菜单(Menu Item)
01.
<code
class
=
"perl"
><code
class
=
"perl"
><code
class
=
"cpp"
>
// 创建菜单
02.
auto menuItem = MenuItemImage::create(
"MenuNormal.png"
,
03.
"MenuSelected.png"
,
04.
CC_CALLBACK_1(HelloWorld::menuCallback,
this
) );
05.
// 设置坐标
06.
menuItem->setPosition( Vec2(x,y) );
07.
// 创建菜单
08.
auto menu = Menu::create(menuItem, NULL);
09.
menu->setPosition(Vec2::ZERO);
10.
this
->addChild(menu,
1
);
11.
</code></code></code>
创建标签(Label)
1.
<code
class
=
"perl"
><code
class
=
"perl"
><code
class
=
"cpp"
><code
class
=
"perl"
>auto label = LabelTTF::create(
"Hello World"
,
"Arial"
,
24
);
2.
label->setPosition(Vec2(x,y));
3.
this
->addChild(label,
1
);
4.
</code></code></code></code>
添加精灵(Sprite)
1.
<code
class
=
"perl"
><code
class
=
"perl"
><code
class
=
"cpp"
><code
class
=
"perl"
><code
class
=
"perl"
>auto sprite = Sprite::create(
"Me.jpg"
);
2.
sprite->setPosition(Vec2(visibleSize.width /
2
, visibleSize.height /
2
));
3.
sprite->setAnchorPoint(Vec2(
0.5
,
0.5
));
4.
this
->addChild(sprite,
0
);
5.
</code></code></code></code></code>
精灵动画(Action)
1.
<code
class
=
"perl"
><code
class
=
"cpp"
><code
class
=
"perl"
><code
class
=
"perl"
><code
class
=
"sql"
>auto actionBy = MoveBy::create(
1
, Point(
100
,
100
));
2.
auto easeAction = EaseIn::create(actionBy,
2
.5f);
3.
sprite->runAction(Repeat::create(easeAction,
5
));
4.
</code></code></code></code></code>
添加监听(Listener)
01.
<code
class
=
"perl"
><code
class
=
"cpp"
><code
class
=
"perl"
><code
class
=
"perl"
><code
class
=
"sql"
><code
class
=
"cpp"
>auto listener1 = EventListenerTouchOneByOne::create();
02.
03.
listener1->onTouchBegan = [](Touch* touch, Event* event){
04.
auto target = static_cast<Sprite*>(event->getCurrentTarget());
05.
Point locationInNode = target->convertToNodeSpace(touch->getLocation());
06.
Size s = target->getContentSize();
07.
Rect rect = Rect(
0
,
0
, s.width, s.height);
08.
if
(rect.containsPoint(locationInNode))
09.
{
10.
log(
"sprite began... x = %f, y = %f"
, locationInNode.x, locationInNode.y);
11.
target->setOpacity(
180
);
12.
return
true
;
13.
}
14.
return
false
;
15.
};
16.
17.
listener1->onTouchMoved = [](Touch* touch, Event* event){
18.
auto target = static_cast<Sprite*>(event->getCurrentTarget());
19.
target->setPosition(target->getPosition() + touch->getDelta());
20.
};
21.
22.
listener1->onTouchEnded = [=](Touch* touch, Event* event){
23.
auto target = static_cast<Sprite*>(event->getCurrentTarget());
24.
if
(target == sprite)
25.
{
26.
log(
"Click on the sprite"
);
27.
}
28.
};
29.
30.
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, sprite);</code></code></code></code></code></code>
0 0
- 学习笔记?
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- 学习笔记
- LeetCode 39.Combination Sum
- hdu2476 String painter(区间dp)
- CodeChef CDMU02(数组辅助查询)
- Fragment应用,及创建选项卡
- CentOS自动获取IP(默认是不开启的)
- 学习笔记
- WOJ-Problem 1014 - Doraemon?s Flashlight
- (C++)用模板或宏实现单例模式
- Java环形缓冲区+生产消费模型及同步开销测试
- HDOJ 1164 Eddy's research I
- 将本地文件复制到复制到Hadoop文件系统
- HDU 3861 The King’s Problem (强连通+二分匹配)
- ubuntu14.04下 openosom svn762 backfire_10.03 编译错误问题修正
- 1009. Product of Polynomials (25)