目的
———了解生命周期
初始化 -》启动完成(启动导演单例 -》 显示视图-》显示场景)
———了解开发 编译 运行 调试
1 执行顺序?
2 如何在界面显示控件?
创建精灵-》设置位置-》添加到父节点(addChild)
3 设置的控件在界面上显示不全?
1> getContentSize.width() or getContentSize.height() ,显示的坐标根据内容高宽做调整。
2> setAnchorPoint() 设置锚点(即,修改控件的中心点),显示的坐标根据内容高宽做调整。
void Node::addChild(Node *child, int zOrder)// zOrder小的显示在底层,zOrder大的显示在顶层。 顶层会覆盖显示底层的控件。
5 调试
1> 在visual studio中
vsIDE自带, 断点 + 单步调试 + 变量值查看
2> 通用,使用CCLog 打印日志
_________________________扩展阅读_________________________
CC_CALLBACK原理及应用
c++ 11基础 :
std::function
类模版std::function是一种通用、多态的函数封装。std::function的实例可以对任何可以调用的目标进行存储、复制、和调用操作,这些目标包括函数、lambda表达式、绑定表达式、以及其它函数对象等。
用法示例:
①保存自由函数
1
2
3
4
5
6
7
8
|
void
printA(
int
a)
{
cout<<a<<endl;
}
std::function<
(
a)>func;
func=printA;
func(2);
|
#include<iostream>
using
namespace
std;
class
A
{
public
:
fun_3(
k,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">m)
{
cout<<k<<
""
<<m<<endl;
}
};
fun(
x,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">y,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">z)
{
cout<<x<<
<<y<<
<<z<<endl;
}
fun_2(
&a,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">&b)
{
a++;
b++;
cout<<a<<
<<b<<endl;
}
main(
argc,
const
char
*argv[])
{
f1();
//print:123
f2=bind(fun,placeholders::_1,placeholders::_2,3);
f2(1,2);
//print:123
f3=bind(fun,3);
//注意:f2和f3的区别。
f3(1,0)!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">//print:213
n=2;
m=3;
f4=bind(fun_2,n,placeholders::_1);
f4(m);
//print:34
cout<<m<<endl;
//print:4说明:bind对于不事先绑定的参数,通过std::placeholders传递的参数是通过引用传递的
cout<<n<<endl;
//print:2说明:bind对于预先绑定的函数参数是通过值传递的
Aa;
f5=bind(&A::fun_3,a,placeholders::_2);
f5(10,20);
//print:1020
,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">)>fc=std::bind(&A::fun_3,std::placeholders::_1,std::placeholders::_2);
fc(10,0)!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">//print:1020
return
0;
}
|
@H_403_228@
CCMenuItemImage*pCloseItem=CCMenuItemImage::create(
"CloseNormal.png"
|
@H_403_228@
closeItem=MenuItemImage::create(
CC_CALLBACK_1(HelloWorld::menuCloseCallback,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">));
|
@H_403_228@
//newcallbacksbasedonC++11
#defineCC_CALLBACK_0(__selector__,__target__,...)std::bind(&__selector__,##__VA_ARGS__)
#defineCC_CALLBACK_1(__selector__,##__VA_ARGS__)
#defineCC_CALCC_CALLBACK_1(HelloWorld::menuCloseCallback,this)LBACK_2(__selector__,std::placeholders::_2,##__VA_ARGS__)
#defineCC_CALLBACK_3(__selector__,std::placeholders::_3##__VA_ARGS__)
|
@H_403_228@
MenuItemImage*MenuItemImage::create(
std::string&normalImage,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">std::string&selectedImage,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">ccMenuCallback&callback)
|
@H_403_228@
HelloWorld::menuCloseCallback(Object*pSender,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important; background:none!important">b)
std::cout<<a<<
<<b<<std::endl;
Director::getInstance()->end();
#if(CC_TARGET_PLATFORM==CC_PLATFORM_IOS)
(0);
#endif
}
|
@H_403_228@
403_228@
注意中其中 指定了两个参数 1 2 运行,在 点击closeItem 的时候,就会输出这两个事先指定的参数 1 2。 那么,不事先指定的参数是在什么时候传入的呢?
|