5.cocos2d锚点
创建一个层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锚点的更多相关文章
- cocos2d anchor point 锚点解析
anchor point 究竟是怎么回事? 之所以造成不容易理解的是因为我们平时看待一个图片是 以图片的中心点 这一个维度来决定图片的位置的.而在cocos2d中决定一个 图片的位置是由两个维度 一个 ...
- cocos2d中锚点概念
这两天看了下锚点的概念. /** * Sets the anchor point in percent. * * anchorPoint is the point around which all t ...
- Cocos2d入门--1--初涉相关属性或代码
Cocos2d vision: cocos2d-x-3.8.1 万丈高楼,起于累土.对于一个游戏框架的学习,其实在于框架功能的使用积累,学会了如何在cocos2d游戏引擎的基础上使用它提供的各种功能 ...
- cocos基础教程(6)坐标与锚点讲解
坐标系详解 Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系.原点为屏幕左下角,x向右,y向上. 世界坐标系(World Coordinate) VS 本地坐标系(Node L ...
- Cocos2d坐标系转换
Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系(高中数学里面那种). 笛卡尔坐标系 笛卡尔坐标系中定义右手系原点在左下角,x向右,y向上,z向外,OpenGL坐标系为笛卡尔右 ...
- 什么是锚点(AnchorPoint)
1.锚点通常是图形的几何中心, AnchorPoint(x,y)的两个参量x和y的取值通常都是0到1之间的实数,表示锚点相对于节点长宽的位置. 例如,把节点左下角作为锚点,值为(0,0): 把节点的中 ...
- 【Cocos2d入门教程七】三分钟看懂Cocos2d坐标系
无论是搞2d还是3d开发,最需要搞清楚的就是坐标系,这部分混乱的话就没啥搞头了.所以玩cocos2d,一上来就需要先把各种与坐标有关的东西搞清楚. 1.OpenGL坐标系 Cocos2d-x使用的是O ...
- Cocos-2d 坐标系及其坐标转换
Cocos-2d中,涉及到4种坐标系: GL坐标系Cocos2D以OpenglES为图形库,所以它使用OpenglES坐标系.GL坐标系原点在屏幕左下角,x轴向右,y轴向上. 屏幕坐标系苹果的Quar ...
- Cocos2d—X游戏开发之CCScrollView(滑动视图)(十二)
CCScrollView在Cocos2d-X引擎中主要使用在图片尺寸远大于屏幕尺寸的时候使用. 总体来说,使用起来比较简单. 一个是CCScrollView控件本身,一个是CCScrollViewDe ...
随机推荐
- CUDA笔记(11)
CUDA提供了一种cudaEvent_t的类型,这种类型Event可以统计GPU上面某一个任务或者代码段的精确运行时间 使用常量内存的光线跟踪器的性能比使用全局内存的性能提升了50% __consta ...
- ViewPager设置不能滚动
设置ViewPager不能滑动 1:设置当前选中的页面 public void setCurrentItem(int item) { mPopulatePending = false; setCurr ...
- Android 学习笔记:Navigation Drawer
laylout文件: <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com ...
- OnClientClick知识+一个上传的例子
文件名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp ...
- shell脚本不同运行方式的差异
说明:以下是个人的见解,不一定都正确,如有错误,欢迎指正! 一,shell脚本的运行方式,最常见的有以下几种: 1 ) . xxx.sh,注意,前面是一个点'.' 2 ) source xxx.sh ...
- Python学习笔记(3)--数据结构之列表list
Python的数据结构有三种:列表.元组和字典 列表(list) 定义:list是处理一组有序项目的数据结构,是可变的数据结构. 初始化:[], [1, 3, 7], ['a', 'c'], [1, ...
- CMSIS-RTOS的使用
CMSIS-RTOS实现通常作为库提供.要将RTOS功能添加到现有的基于CMSIS的应用程序,需要添加RTOS库(通常是配置文件).RTOS库的可用功能在头文件cmsis_os.h中定义,该文件特定于 ...
- 安装Orcacle后使用DBCA(Database Configuration Assistant)卡住的问题
转自:http://hi.baidu.com/kissbaofish/item/2f56d326742c39454799620b 用dbca建库停在46% 是export NLS_LANG='amer ...
- OpenGL之抗锯齿 以及 线宽的设置
转自原文 OpenGL之抗锯齿 以及 线宽的设置 抗锯齿 1.线的抗锯齿 glEnable(GL_LINE_SMOOTH); //启用 glHint(GL_LINE_SMOOTH,GL_NICEST) ...
- Android:管理应用内存
全部内容均来源于官方文档https://developer.android.com/training/articles/memory.html only way to completely relea ...