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 ...
随机推荐
- springmvc 1.接受日期类型的参数 2.后台返回json串的格式处理(返回json串null值处理为"")
springmvc中的配置: <bean id="dateConvert" class="com.iomp.util.DateConvert"/> ...
- 使用与不适用@RequestBody注解的区别
1. 如果使用@RequestBody接受页面参数: public Map<String,Object> insertBudget(@ApiParam(required = true,na ...
- Android Gallery和ImageSwitcher同步自动(滚动)播放图片库
本文主要内容是如何让Gallery和ImageSwitcher控件能够同步自动播放图片集 ,看起来较难,然而,实现的方法非常简单, 请跟我慢慢来.总的来说,本文要实现的效果如下图:(截图效果不怎么好) ...
- angularjs 学习理解
1AngularJS 是一个 JavaScript 框架.它是一个以 JavaScript 编写的库. 2 ng-app 指令定义一个 AngularJS 应用程序.ng-model 指令把元素值(比 ...
- Windows10显示桌面我的电脑等图标
1.桌面右键,选择最后一项:个性化 2. 选择:主题 --> 桌面图标设置 3. 将需要显示的图标勾上就可以啦.
- 【agc004f】Namori Grundy
那个问一下有人可以解释以下这个做法嘛,看不太懂QwQ~ Description 有一个n个点n条边的有向图,点的编号为从1到n. 给出一个数组p,表明有(p1,1),(p2,2),…,(pn,n)这n ...
- 苹果下一代iPhone曝光
3月23日消息,据9TO5Mac报道,苹果下一代iPhone(以下暂命名为iPhone 11)可能会提供像三星Galaxy S10的PowerShare功能,能为Apple Watch和AirPods ...
- Python学习七步走
在周五的下午三点钟(为什么是这个时间?因为事情总会在周五下午三点钟发生),你收到一条通知,客户发现你的软件出现一个错误.在有了初步的怀疑后,你联系运维,查看你的软件日志以了解发生了什么,因为你记得收到 ...
- Node实现简单的注册时后端的MVC模型架构
实现一个简单的注册界面后端MVC模型架构 第一步:在生成的express框架的app.js中添加一个路由,代码如下:var api = require('./routes/api'); app.use ...
- COGS——T 8. 备用交换机
http://www.cogs.pro/cogs/problem/problem.php?pid=8 ★★ 输入文件:gd.in 输出文件:gd.out 简单对比时间限制:1 s 内存 ...