Cocos2d-x之getVisibleSize,getContentSize,boundingBox,getContentSizeInPixels,convertToGL,convertToUI

getVisiblesize()和getVisibleOrigin可视分辨率的算法,以及适配后设计分辨率发生变化!         当知道了getWinSize是自己的设计分辨率 ,getFrameSize是设备分辨率后,还有知道资源的分辨率一般是参考设计分辨率,如果是设备分辨率宽高比等于设计分辨率宽高比,那么不管哪种适配方式资源图片都能正常缩放铺满屏幕,只是分辨率效果不同而已,此时visibleSize也等于屏幕分辨率SIZE,但如果是设备分辨率的宽高比和设计分辨率宽高比不一致时,这时候visibleSize... 阅读详情
    CCNode类的setPosition,getPosition函数如果是一个Node的Child则获取的坐标就是该Node的本地坐标
另一个关键问题就是在cocos2d-x里就是各种对象的大小问题。因为在cocos2d-x里CCNode对象有缩放的方法setScaleX和setScaleY。所以在获取对象大小的时候必须根据情况明确指定获取对象原始大小,还是缩放后的大小。当然cocos2d-x里提供了对应函数来完成这些操作:
getContentSize函数来获得节点原始的大小。只是逻辑尺寸,不是像素
boundingBox函数来获得经过缩放和旋转之后的外框盒大小。
getContentSizeInPixels获得的是像素点大小

像素点和逻辑点关系:逻辑点大小 = 像素大小/contentScaleFactor.
getVisibleSize:默示获得视口(可视区域)的大小,若是DesignResolutionSize跟屏幕尺寸一样大,则getVisibleSize便是getWinSize。
getVisibleOrigin:默示可视区域的出发点坐标,这在处理惩罚相对地位的时辰很是有效,确保节点在不合辨别率下的地位一致。
坐标转换:

GL坐标系,cocos2d-x默认坐标系:

CCPoint CCDirector::convertToGL(const CCPoint& uiPoint)
{
     CCSize s = m_obWinSizeInPoints;
     float newY = s.height - uiPoint.y;
}
屏幕坐标系:   默认原点在左上角
CCPoint CCDirector::convertToUI(const CCPoint& glPoint)
{
     CCSize winSize = m_obWinSizeInPoints;
     float oppositeY = winSize.height - glPoint.y;

     return ccp(glPoint.x,oppositeY);
}

两种坐标的X方向没有变,只变了Y方向,cocos2d-x里默认的GL坐标系,即左下角为原点ccp(0.0f,0.0f)

cocos2d-x getContentSize和getContentSizeInPixels区别 NULL 博文链接:https://buerkai.iteye.com/blog/1545142 立即下载

相关推荐

Flutter 中使用蓝牙插件报错,说没有权限怎么解决

2、在build.grale里面更改一下版本号,我修改的是targetSdkVersion这个版本号,需要根据你自己的版本进行更改,记得更改之后先flutter clean一下再run。搞了一晚上,没搞出来,第二天用同事手机测试发现他手机可以,我手机还是不行,才发现是Android版本问题,需要修改两处地方。废话不多说,咱先看报错信息。

zzj17637822814的博客 2289

getVisibleSize 和 getContentSize 和 getWinSize

getVisibleSize:获得视口(可视区域)的大小,若是DesignResolutionSize跟屏幕尺寸一样大,则getVisibleSize便是getWinSize。 getVisibleOrigin:获得可视区域的出发点坐标,在处理相对位置时,确保节点在不同分辨率下的位置一致。 在cocos2d-x里CCNode对象有缩放的方法setScaleX和setScaleY。所以在

雨月琉琉的专栏 1万+

阿里云一键登录Java后端实战:5分钟搞定号码认证服务集成(附完整代码)

本文详细介绍了如何在Java后端项目中快速集成阿里云号码认证服务(PNVS),实现高效、安全的一键登录功能。文章从核心架构、安全机制解析入手,提供了完整的Maven依赖配置、服务端环境准备、核心业务逻辑实现(包括Token验证、用户处理、异常降级)以及生产环境下的性能优化、监控与部署方案,并附有可直接使用的完整代码示例。

p1q2r的博客 845

cocos2dx getContentSize

假如使用一张图创建了一个精灵,图片的大小120*120,缩放先后通过getContentSize获取的大小不变,所以如果 使用相对位置,需要考虑到缩放。 before scale getContentSize: width = 120 before scale getContentSize: height = 120 after scale getContentSize:

思考的智慧,知识源于思考 3302

AntV G6避坑指南:折叠树状图那些意想不到的BUG(附解决方案)

本文深入剖析了在React项目中使用AntV G6实现折叠树状图时,从图标错乱、数据同步到状态管理的常见BUG与解决方案。文章基于实战经验,详细解读了G6的内部机制,提供了从环境配置、自定义节点绘制到事件处理与性能优化的完整避坑指南,帮助开发者彻底解决折叠展开功能的疑难杂症。

wasm7browser的博客 256

DeepSeek与豆包无缝对接:5分钟搞定智能周报自动化(附完整代码)

本文详细介绍了如何利用DeepSeek与豆包API,快速搭建一个智能周报自动化系统。通过整合豆包平台的工作流数据,并调用DeepSeek大模型进行深度分析与内容生成,该系统能在5分钟内自动抓取、分析多源信息,并生成结构清晰、富有洞察力的团队周报,显著提升工作效率。

weixin_29029995的博客 493

cocos2d-x 中 getContentSize

getContentSize 只有对精灵才能起到作用。尽管经常是 CCNode中包含一个CCSprite但是 CCNode的getContentSize是 0 0 所以需要通过CCSprite中获取出来

cjopengler的专栏 3179

史上最牛逼的导航网站(很全很详细)

今天,给大家推荐47个聚合型的导航网站 每一个都收录上百个网站,1个能顶100个,丝毫没有夸张的成分。 (推荐收藏) 设计师导航网站 01 优设导航 https://hao.uisdc.com/ 设计师必备的导航网站,包含设计工具、素材资源、字体设计、配色方案、酷站模板等。 界面清晰无广告,收录网站超过520个。 02 设计导航 http://h...

孙叫兽的博客 7万+

cocos2d-x3.2中的getVisibleSize,getContentSize,boundingBox,getContentSizeInPixels,convertToGL,convertTo

Node类的setPosition,getPosition函数如果是一个Node的Child则获取的坐标就是该Node的本地坐标 另一个关键问题就是在cocos2d-x里就是各种对象的大小问题。因为在cocos2d-x里Node对象有缩放的方法setScaleX和setScaleY。所以在获取对象大小的时候必须根据情况明确指定获取对象原始大小,还是缩放后的大小。当然cocos2d-x里提供了对应...

菲菲家的吴先森 1775

养龙虾之_因特尔UHD/ULtra/Arc核显跑大模型_安装ollama_跑qwen3.5:0.8b/9b_使用copaw1.0.1测试_并配置copaw技能效果炸裂---AI大模型应用探索0019

摘要:本文探讨了利用Intel UHD770核显运行大语言模型的可能性。通过使用Intel发布的ipex-llm项目工具包,成功在核显上运行了Qwen3.5系列模型。测试发现0.8B小模型运行流畅(3-5秒响应),但智能程度有限;而9B大模型虽然效果更好,但响应时间长达2分钟,且GPU/CPU占用率不高。实验证明Intel核显确实可以运行LLM,但实际效果和性能表现仍有提升空间,特别是对大模型的支持尚不理想。

添柴程序猿的专栏 235

YOLO26改进策略【YOLO和Mamba】| 替换骨干 Mamba-YOLO26-L !!! 最新的发文热点

Vision Clue Merge模块在Mamba - YOLO模型中同样重要,主要负责在模型的下采样过程中处理特征图,为后续的特征融合和目标检测任务提供更有效的信息。

Limiiiing的博客 472

cocos2d-x getVisibleSize、getContentSize、getWinSize函数

在cocos2d-x里CCNode对象有缩放的方法setScaleX和setScaleY。所以在获取对象大小的时候必须根据情况明确指定获取对象原始大小,还是缩放后的大小。 cocos2d::Size size1 = cocos2d::CCDirector::getInstance()->getWinSize(); float scaleX=size1.width/768; float ...

南风古 2730

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

cocos2d-x3.2总结(三)TMXTileMap::getContentSize与getMapSize*getTileSize的积的异同

当你使用

cbbbc 3301

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

cocos2dx 3.x getVisibleSize 和 getContentSize 和 getWinSize 和 getVisibleOrigin

getVisibleSize:获得视口(可视区域)的大小 getVisibleOrigin:逻辑区域的大小,比如为了适应屏幕时会等比例缩小或者放大,这个时候就可能在屏幕上出现 部分区域是空的(黑的),而此时的游戏画面的大小就是这个getVisibleOrigin。 getVisibleOrigin:逻辑区域大小的(0,0)点在屏幕上的位置,即getVisibleOrigin里面的(...

weixin_30834783的博客 352

cocos2dx 的基本概念 ContentSize/AnchorPoint/Bounds/Frame

转自:https://www.jianshu.com/p/c15c915d2e57 下图展示了bounds和frame的区别:

haima1998的专栏 400

cocos2dx_实例分析getBoundingBox和getContentSize

1:分析BoundingBox. 首先来看这样一段代码,其中HelloWorld的图片大小为195*270 Node* pNode = Node::create(); addChild(pNode); Sprite* pSprite1 = Sprite::create(&amp;quot;HelloWorld.png&amp;quot;); pNode-&amp;amp;gt;addChild(pSprite1); Rect rt1 = pSpr...

qq_31480839的博客 4366

Cocos2d-x 3.x getContentSize、getBoundingBox区别,灵活运用于碰撞检测

在很多碰撞检测中经常可以看到它,getContentSize,还有它getBoundingBox的影子。为了具体搞清楚这些细节的东西,写了点代码,测试下。如下图   给一个精灵(100*100),放到它的大小,然后输出值。     getContentSize很容易理解,就是获取到当前物体的大小,但是要注意是本身大小,无论是是缩放还是缩小了,其获取的还是它原来的本身大小。所以放到后还是...

ylwdi的专栏 1572

<Xcode><初学><备忘>convertToGL 和convertToNodeSpace的作用

coco2dx中屏幕坐标系是以左上角为原点的坐标系,而常用的openGL坐标系是右手坐标系,简单来说就是左下角为原点,所以在接收触摸事件时需要使用convertToGL使得触点坐标转为为openGL坐标方便使用。 convertToNodeSpace,我一开始同时接触这两个关键字的时候以为这是openGL的反向操作……看完说明才知道这是将一个坐标点转化到一个图层的坐标系中。  

u012826571的专栏 1171

cocos2d-x getVisibleSize、getFrameSize理解

首先要理解visibleSize和frameSize的意义: frameSize: local director = cc.Director:getInstance() local view =director:getOpenGLView() local frameSize =view:getFrameSize() local w,h =frameSize.width,frameS...

u012861978的专栏 2949

Cocos2d-x-Lua出乎意料的性能短板——那个getPosition的binding

这次要来说一个吹水的话题,关于性能方面,最近在用Cocos2d-x + Lua写一个小游戏,因为实在太简单,就完全没想过会有什么掉帧的情况。 结果一到手机上运行,在关卡场景里的帧率立刻降低了,大概只有16到30帧,这个帧率对这个游戏来说,实在是有点可怕。 找了一下原因,凶手是某个update函数,因为每帧都要调用,遍历200到400个对象,主要是做碰撞检测,就在这里帧率下降了一半。 优化也很

cbbbc 2044
上一篇: 关于cocos2dx 2.0.3 及以上找不到org.cocos2dx.lib库的解决
下一篇: Cocos2d-x之onEnter与init
i丹明扬
博客等级 码龄15年 331粉丝 115原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值