❤️初识cocoas 2D -x

**************************************************

❤️游戏引擎

超大的第三方库,主要由四个关键因素:

①导演 Director

②场景 Scene   

③图层 Layer

④精灵  Sprite


一个导演有多个场景

同一个时间点 一个界面只有一个场景  

一个场景有多个图层

一个图层有多个精灵


**************************************************

director->setOpenGLView(eglView);

相当于makeKeyvisible

一般在delegate中的写法是差不多的


**************************************************

❤️添加精灵步骤:


①创建精灵

Sprite::create("hero1.png")

②设置精灵的位置

Sprite->setPosition(

③将精灵添加到当前图层

this->addChild(

**************************************************

❤️刷新

设置刷新频率

director->setAnimationInterval(1.0 / 60);

令当前对象在每一帧刷新的时候  回调update方法

this->scheduleUpdate();

this->unscheduleUpdate();

**************************************************

❤️给精灵添加动作步骤:

①创建action

MoveTo* MoveTo::create(float duration, const Point& position)

②精灵调用方法运行action

Action * Node::runAction(Action* action)

③精灵停止action

void Node::stopAllActions()



**************************************************

❤️获取屏幕点击事件

EventListenerTouchOneByOne

①创建一个点击事件监听器

EventListenerTouchOneByOne* EventListenerTouchOneByOne::create()

②创建监听响应函数

void EventListenerTouchOneByOne::setSwallowTouches(bool needSwallow)


③添加监听响应函数

 pListener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);

④添加监听器到当前图层

_eventDispatcher调用

void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* listener, Node* node)


※注意:要重写touch对应的方法

bool Layer::onTouchBegan(Touch *touch, Event *unused_event)


**************************************************

❤️常用类和方法

※class CC_DLL Size


※class CC_DLL Point


※typedef Point Vect;

这个vect重载了+-运算符


※class CC_DLL Node : public Object

※class CC_DLL Layer : public Node

void Node::onEnter()

Point Node::convertTouchToNodeSpace(Touch *touch) const



※class CC_DLL Sprite : public NodeRGBA, public TextureProtocol

Sprite* Sprite::create(const std::string& filename)

void Sprite::setPosition(const Point& pos)

void Sprite::addChild(Node* child)

const Point& Node::getPosition() const

void Node::removeFromParent()

void Node::setTag(int var)



※math.h

extern double fabs(double);


※class CC_DLL Array : public Object, public Clonable

long count() const


long Array::getIndexOfObject(Object* object) const




*****************************

❤️注意


※cocoas2D是MRC

所以要考虑内存泄露的问题


※原点在左下角








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值