cocos2dx day 1

原文:http://www.cocos2d-x.org/programmersguide/2/index.html

一、Basic Concepts

1.director

2.scene

2.1 scene graph

negative,从左边开始画,positive,从右边开始画

// Adds a child with the z-order of -2, that means
// it goes to the "left" side of the tree (because it is negative)
scene->addChild(title_node, -); // When you don't specify the z-order, it will use 0
scene->addChild(label_node); // Adds a child with the z-order of 1, that means
// it goes to the "right" side of the tree (because it is positive)
scene->addChild(sprite_node, );

3.node/sprite/label

3.1 sprite

可以给玩家操控的对象,新建一个sprite并且设置他的属性。

// This is how to create a sprite
auto mySprite = Sprite::create("mysprite.png"); // this is how to change the properties of the sprite
mySprite->setPosition(Vec2(, )); mySprite->setRotation(); mySprite->setScale(2.0); // sets scale X and Y uniformly//设置图片大小 mySprite->setAnchorPoint(Vec2(, ));

4.Action

4.1 moveto和moveby的区别(网上查的答案,后面有空再仔细研究,先扫盲)

moveto:移动到的坐标点,调用reverse方法,可以朝反向移动。

moveby:相对于node现在的坐标点,也有reverse方法,但是调用会报错,难道是bug?4.2 Sequence当需要sprite或者Node做连续动作时,可以在runAction里面用Sequence

auto myNode = Node::create()

auto moveTo1 = MoveTo::create(, Vec2(,));
auto moveBy1 = MoveBy::create(, Vec2(,));
auto moveTo2 = MoveTo::create(, Vec2(,)); myNode->runAction(Spawn::create(moveTo1, moveBy1, moveTo2, nullptr));

但是在create方法里面,不加最后一个参数,nullptr居然会报错,不明白。

上一篇:tp剩余未验证内容-4


下一篇:css总结