11.了解自定义命名空间的创建及用法
这个不会。搬运小熊学长的代码...
main.cpp
#include <iostream>
#include "namespace.h"
using namespace std;
using namespace pers;
using namespace debts;
void other()
{
Person pr = {"Doodles","Glister"};
ShowPerson(pr);
cout << endl;
Debt zippy[3];
for(int i=0;i!=3;i++)
{
GetDebt(zippy[i]);
}
for(int i=0;i!=3;i++)
{
ShowDebt(zippy[i]);
}
cout << "Total debts is: " << SumDebt(zippy,3) << endl;
}
int main(int argc, char** argv) {
Debt debt = {{"Zhang","Fei"},2222.0};
ShowDebt(debt);
other();
return 0;
}
namespace.h:
#ifndef NAME_SPACE_H
#define NAME_SPACE_H
#include <string>
namespace pers{
struct Person{
std::string fname;
std::string lname;
};
void GetPerson(Person &);
void ShowPerson(const Person &);
}
namespace debts
{
using namespace pers;
struct Debt
{
Person name;
double amount;
};
void GetDebt(Debt &);
void ShowDebt(const Debt &);
double SumDebt(const Debt ar[],int n);
}
#endif
namespace.cpp
#include <iostream>
#include "namespace.h"
namespace pers
{
void GetPerson(Person & per)
{
std::cout << "Enter first name:";
std::cin >> per.fname;
std::cout << "Enter last name:";
std::cin >> per.lname;
}
void ShowPerson(const Person & per)
{
std::cout << per.lname<<","<<per.fname;
}
}
namespace debts
{
void GetDebt(Debt & debt)
{
GetPerson(debt.name);
std::cout << "Enter debt:";
std::cin >> debt.amount;
}
void ShowDebt(const Debt & debt)
{
ShowPerson(debt.name);
std::cout << ":$" << debt.amount << std::endl;
}
double SumDebt(const Debt ar[],int n)
{
double total = 0;
for(int i=0;i!=n;i++)
{
total += ar[i].amount;
}
return total;
}
}
12.掌握对精灵位移 缩放 旋转的控制方法
这些都有By和To 两者区别:前者是相对的 后者是绝对的
exp:
auto moveto = MoveTo::create(2,Vec2(200,200));
sprite->runAction(moveto);
auto moveby = MoveBy::create(2,Vec2(200,200));
sprite->runAction(moveBy);
//执行效果;第一个参数是持续时间,Vec2中的终点坐标;
auto scaleto = ScaleTo::create(2,0.5,0.5);
sprite->runAction(scaleto);
auto scaleto = ScaleBy::create(2,0.5,0.5);
sprite->runAction(scaleby);
////第一个参数是持续时间,第二个参数是缩放的倍数
以此类推
13.了解物理引擎碰撞监听器的创建
使用Box2D创建物理引擎的一般步骤:
创建物理世界->指定世界的边界->创建世界的物体->创建形状->创建夹具->使用夹具把形状固定到物体上->连接精灵与物体->检测碰撞
//物理世界的场景
auto scene = Scene::createWithPhysics();
//重力:
Vect gravity(0, -0.5f);
scene->getPhysicsWorld()->setGravity(gravity);
//用最简单的方式创建刚体
auto body = PhysicsBody::createEdgeBox(Size(visibleSize.width, visibleSize.height), PHYSICSBODY_MATERIAL_DEFAULT, 3);
//让刚体加入到物理世界
auto node = Node::create();
node->setPosition(Point(visibleSize.width / 2, visibleSize.height / 2));
node->setPhysicsBody(body);
scene->addChild(node);
https://blog.youkuaiyun.com/tonny_guan/article/details/39584055
1:创建一个物理世界
Word=new b2World(b2Vec2(0,-10));
2: 创建一个运动的物体
//定义物理世界边界
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0);
b2Body *groundBody = world->CreateBody(&groundBodyDef);
14.掌握cocos2d中的内存管理机制中引用技术机制的核心内容
当创建一个对象实例并在堆上分配内存时,对象的引用计数加一,有其他对象也加一。
其他对象不再持有该共享对象时,引用计数减一。
引用计数变为0,对象内存立刻被释放。
retain() 引用计数加一
release() 引用计数减一
autorelease() 将对象放入自动释放池
15.掌握触摸事件(单点和多点)响应函数及事件与对象的绑定
多点不会怎么办...感觉很抽象的样子
this->setTouchEnable(true);
//注册监听
CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this,0);
16.掌握精灵显示层次和坐标的关系
精灵的层次和坐标系中的z轴有关
默认是越先越优先
数字越大越优先
17.掌握动作序列的简单使用
Sequence是按照顺序去执行 Swapn是同时执行 都以NULL结尾
auto sec = Sequence::create(moveby,moveto,NULL);
sp1->runAction(sec);
auto spn = Swapn::create(moveto,scaleto,NULL);
sp1->runAction(spn);
18.掌握新工程的创建方法
cocos new 工程名 -l 语言 -d 路径 -p 包名
exp:cocos new iegame -l cpp -d E:\ -p com.pool
19.掌握父物体对子物体的影响(主要是坐标)
应该是对父物体怎么样,在绝对世界中,子物体也会怎样吧…
比如旋转:父物体旋转90度,子物体也会旋转90度,但是其实它们之间相对的是没有变化的.
例如:对父节点设置scale属性,其子节点也会被设置和父节点相同的scale属性。
PS.以上没有验证过…
20.掌握创建新类的核心代码以及意义(如何从头创建一个新类 并纳入到cocos2d-x内存管理机制中)CREATE_FUNC
exp: 创建一个HelloWorld类
HelloWorld.h
#ifndef _HELLOWORLD_H__
#define _HELLOWORLD_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::Scene
{
public:
HelloWorld();
~HelloWorld();
public:
static cocos2d::Scene* createScene();
virtual bool init();
CREATE_FUNC(HelloWorld);
};
#endif//__HELLOWORLD_H__
HelloWorld.cpp
#include"HelloWorld.h"
USING_NS_CC;
HelloWorld::HelloWorld()
{
}
HelloWorld::~HelloWorld()
{
}
Scene* HelloWorld::createScene()
{
return HelloWorld::create();
}
bool HelloWorld::init()
{
if(!Scene::init())
{
return false;
}
....
return true;
}