zoukankan      html  css  js  c++  java
  • cocos2d中的anchorPoint属性详解

    原文地址:http://www.tuicool.com/articles/ANVjMj

    1> anchorPoint对position的影响

    anchorPoint的作用就是相当于确定在子节点的哪一个位置上使用父节点的position这个属性。

    如果anchorPoint = (0, 0),那么节点的左下角就会在position属性指定的位置上

    如果anchorPoint = (0.5, 0.5),那么节点的中心点就会在position属性指定的位置上

    如果anchorPoint = (1, 1),那么节点的右上角就会在position属性指定的位置上

    anchorPoint为其他值,以此类推

    下面画图解释一下

    // 红色(red)是蓝色的子节点,所以是以蓝色的左下角位置为坐标原点(0, 0)。假设蓝色的大小是100x100,红色的大小是50x50
    red.position = CGPointMake(50, 50); // 可以看出,(50, 50)是在蓝色的正中间

    2> anchorPoint对缩放的影响

    我先做个总结:

    * 如果anchorPoint = (0, 0),那么节点就会绕着自己的左下角进行缩放

    * 如果anchorPoint = (0.5, 0.5),那么节点 就会绕着自己 的中点 进行缩放 

    * 如果anchorPoint = (1, 1),那么节点 就会绕着自己 的右上角 进行缩放

    * anchorPoint为其他值,以此类推

    下面画图解释一下 

    node.scale = 0.5f; // 宽高变为原来的1/2

    蓝色代表缩放前,红色代表缩放后

    3> anchorPoint对旋转的影响

    我先做个总结:

    * 如果anchorPoint = (0, 0),那么节点就会绕着自己的左下角进行 旋转

    * 如果anchorPoint = (0.5, 0.5),那么节点 就会绕着自己 的中点 进行 旋转 

    * 如果anchorPoint = (1, 1),那么节点 就会绕着自己 的右上角 进行 旋转

    * anchorPoint为其他值,以此类推

    下面画图解释一下

    node.rotation = 45; // 顺时针旋转45°

    蓝色代表旋转前,红色代表旋转后 

     

    4>这个属性决定了anchorPoint是否要影响position 

    @property(nonatomic,readwrite,assign) BOOL isRelativeAnchorPoint;

    * 如果为YES,代表anchorPoint影响position;如果为NO,代表anchorPoint不影响position,那么节点的左下角就会在position属性指定的位置上

    * 默认情况下,CCSprite的isRelativeAnchorPoint为YES,CCScene、CCLayer的isRelativeAnchorPoint为NO

  • 相关阅读:
    XTU 1250 Super Fast Fourier Transform
    XTU 1249 Rolling Variance
    XTU 1243 2016
    CodeForces 710A King Moves
    CodeForces 710B Optimal Point on a Line
    HDU 4472 Count
    并查集
    高精度四件套
    Kruskal最小生成树
    [蓝桥杯]翻硬币(贪心的详解附带题目测试链接)
  • 原文地址:https://www.cnblogs.com/baozou/p/3307581.html
Copyright © 2011-2022 走看看