创建一个层T1LayerAnchorPoint

  • AppDelegate.cpp

     bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
    glview = GLViewImpl::createWithRect("MyLayer", Rect(, , , ));
    director->setOpenGLView(glview);
    } director->getOpenGLView()->setDesignResolutionSize(, , ResolutionPolicy::SHOW_ALL); // turn on display FPS
    director->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / ); FileUtils::getInstance()->addSearchPath("res"); // create a scene. it's an autorelease object
    //auto scene = HelloWorld::createScene(); //CCScene *pScene = MyScene::create();
    CCScene *pScene = T1LayerAnchorPoint::scene();

    // run
    director->runWithScene(pScene);

    return true;
    }
  • T1LayerAnchorPoint.h
     #pragma once
    #include "cocos2d.h"
    USING_NS_CC; class T1LayerAnchorPoint:public CCLayer
    {
    public:
    //create->init
    static T1LayerAnchorPoint*create();
    bool init();
    static CCScene *scene(); //画线
    virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4& transform, uint32_t flags);
    };
  • T1LayerAnchorPoint.cpp
     #include "T1LayerAnchorPoint.h"
    
     //创建层
    T1LayerAnchorPoint*T1LayerAnchorPoint::create()
    {
    T1LayerAnchorPoint *pRet = new T1LayerAnchorPoint();
    if (pRet && pRet->init())
    {
    pRet->autorelease();
    }
    else
    {
    delete pRet;
    pRet = NULL;
    }
    return pRet; } //初始化层
    bool T1LayerAnchorPoint::init()
    {
    CCLayer::init(); CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCSprite *spr = CCSprite::create("anchor3.png");
    //设置锚点
    spr->setAnchorPoint(ccp(, ));
    spr->setPosition(ccp(winSize.width / , winSize.height / ));
    addChild(spr);
    return true;
    } CCScene *T1LayerAnchorPoint::scene()
    {
    CCScene *scene = CCScene::create();
    T1LayerAnchorPoint *layer = T1LayerAnchorPoint::create();
    scene->addChild(layer);
    return scene;
    } void T1LayerAnchorPoint::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4& transform, uint32_t flags)
    {
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    ccDrawColor4B(, , , ); ccDrawLine(ccp(, winSize.height / ), ccp(winSize.width, winSize.height / ));
    ccDrawLine(ccp(winSize.width / , ), ccp(winSize.width / , winSize.height));
    }

5.cocos2d锚点的更多相关文章

  1. cocos2d anchor point 锚点解析

    anchor point 究竟是怎么回事? 之所以造成不容易理解的是因为我们平时看待一个图片是 以图片的中心点 这一个维度来决定图片的位置的.而在cocos2d中决定一个 图片的位置是由两个维度 一个 ...

  2. cocos2d中锚点概念

    这两天看了下锚点的概念. /** * Sets the anchor point in percent. * * anchorPoint is the point around which all t ...

  3. Cocos2d入门--1--初涉相关属性或代码

    Cocos2d vision:  cocos2d-x-3.8.1 万丈高楼,起于累土.对于一个游戏框架的学习,其实在于框架功能的使用积累,学会了如何在cocos2d游戏引擎的基础上使用它提供的各种功能 ...

  4. cocos基础教程(6)坐标与锚点讲解

    坐标系详解 Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系.原点为屏幕左下角,x向右,y向上. 世界坐标系(World Coordinate) VS 本地坐标系(Node L ...

  5. Cocos2d坐标系转换

    Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系(高中数学里面那种). 笛卡尔坐标系 笛卡尔坐标系中定义右手系原点在左下角,x向右,y向上,z向外,OpenGL坐标系为笛卡尔右 ...

  6. 什么是锚点(AnchorPoint)

    1.锚点通常是图形的几何中心, AnchorPoint(x,y)的两个参量x和y的取值通常都是0到1之间的实数,表示锚点相对于节点长宽的位置. 例如,把节点左下角作为锚点,值为(0,0): 把节点的中 ...

  7. 【Cocos2d入门教程七】三分钟看懂Cocos2d坐标系

    无论是搞2d还是3d开发,最需要搞清楚的就是坐标系,这部分混乱的话就没啥搞头了.所以玩cocos2d,一上来就需要先把各种与坐标有关的东西搞清楚. 1.OpenGL坐标系 Cocos2d-x使用的是O ...

  8. Cocos-2d 坐标系及其坐标转换

    Cocos-2d中,涉及到4种坐标系: GL坐标系Cocos2D以OpenglES为图形库,所以它使用OpenglES坐标系.GL坐标系原点在屏幕左下角,x轴向右,y轴向上. 屏幕坐标系苹果的Quar ...

  9. Cocos2d—X游戏开发之CCScrollView(滑动视图)(十二)

    CCScrollView在Cocos2d-X引擎中主要使用在图片尺寸远大于屏幕尺寸的时候使用. 总体来说,使用起来比较简单. 一个是CCScrollView控件本身,一个是CCScrollViewDe ...

随机推荐

  1. HDU 3342 Legal or Not(判断环)

    Problem Description ACM-DIY is a large QQ group where many excellent acmers get together. It is so h ...

  2. 隐私:随机选择 MAC 地址

    隐私:随机选择 MAC 地址 从 Android 8.0 开始,Android 设备在未连接到网络的情况下探测新网络时会使用随机 MAC 地址. 在 Android 9 中,您可以启用开发者选项(默认 ...

  3. 四、YOLO-V1原理与实现(you only look once)

    可以看成图像分类与定位的结合,给定一张图片,目标检测系统要能够识别出图片的目标并给出其位置,由于图片中目标数是不定的,且要给出目标的精确位置,目标检测相比分类任务更复杂.目标检测的一个实际应用场景就是 ...

  4. CF 986C AND Graph(建模+DFS)

    #include<stdio.h> ],v[]; ],n,al; void dfs(int x){ if(v[x])return; v[x]=; if(ex[x])dfs(al^x); ; ...

  5. CentOS7.3 下开放防火墙的端口

    CentOS 7.3默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1:关闭firewall: systemctl stop firewalld.service system ...

  6. 紫书 习题 10-3 UVa 1643(计算几何 叉乘)

    直观感觉对角线重合的时候面积最大 然后可以根据方程和割补算出阴影部分的面积 注意知道两点坐标,可以求出与原点形成的三角形的面积 用叉乘,叉乘的几何意义以这两个向量为边的平行四边形的面积 所以用叉乘除以 ...

  7. EXPIREAT

    EXPIREAT key timestamp EXPIREAT 的作用和EXPIRE类似,都用于为key设置生存时间. 不同在于EXPIREAT命令接受都时间参数是UNIX时间戳(unix times ...

  8. 洛谷 P1703 那个什么密码2

    P1703 那个什么密码2 题目背景 https://www.luogu.org/problem/show?pid=1079 题目描述 与原题一模一样.具体不同请见输入格式 输入输出格式 输入格式: ...

  9. Android 中图能够用到的图片处理类 BitmapUtils

    Android在实际开发中非常多时候都要对图片进行一定的处理,这里总结的BitmapUtils 类包含一下几个功能: 1.Android图片倒影, 2.Android图片模糊处理, 3.Android ...

  10. 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT

    2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...