原文: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, -2); // 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, 1);
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(500, 0)); mySprite->setRotation(40); mySprite->setScale(2.0); // sets scale X and Y uniformly//设置图片大小 mySprite->setAnchorPoint(Vec2(0, 0));
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(2, Vec2(50,10)); auto moveBy1 = MoveBy::create(2, Vec2(100,10)); auto moveTo2 = MoveTo::create(2, Vec2(150,10)); myNode->runAction(Spawn::create(moveTo1, moveBy1, moveTo2, nullptr));
但是在create方法里面,不加最后一个参数,nullptr居然会报错,不明白。
时间: 2024-10-05 11:41:09