首页 技术 正文
技术 2022年11月14日
0 收藏 542 点赞 3,910 浏览 1002 个字

坐标系:
游戏开发中。全部物体都有自己的位置,而我们须要一个參考系来描写叙述物体的位置。使用cocos2d-x开发的时候。有几个比較重要坐标系须要掌握:屏幕坐标系和Cocos2d坐标系
屏幕坐标系:这个是ios、android、wp手机屏幕使用的坐标系,该坐标系以左上角为坐标原点,X轴正向为右,Y轴正向为下。也就是说。屏幕左上角坐标为(0,0)。屏幕右下角坐标为(width。height)。
须要注意。ios/android上面的touch事件。使用的是屏幕坐标系。须要使用Touch的getLocation()转换为cocos2d坐标系。
void OptionLayer ::onTouchesBegan( const std:: vector< Touch*>& touches, Event * event){        Point pt = touches.at(0)->getLocation();}
Cocos2d坐标系:这个是游戏中使用的坐标系,我们在描写叙述Position时以该坐标系作为參考,左下角为坐标原点。X轴正向为右。Y轴正向为上。也就是说,屏幕左下角坐标为(0。0),屏幕右上角坐标为(width。height)。
AnchorPoint(锚点):cocos2d中物体显示的位置由两个參数决定:Position和AnchorPoint。

这里有一个计算公式:real.x = Position.x + (AnchorPoint.x – 0.5 ) * width;
AnchorPoint是一个矢量,取值范围是(0,0)到(1。1)。

能够这样来理解AnchorPoint:想象我们有一个“图钉”。在物体的表面有个坐标系:X轴向右,Y轴向上(与cocos2d坐标系同样)。物体的左下角为其原点(0,0),物体右上角坐标为(1。1),依据AnchorPoint的值,把图钉按到物体表面,然后,把图钉按到物体的Position的位置,这个过程在游戏中被成为“贴图”。

默认情况下,物体的AnchorPoint为(0.5,0.5)。可是Layout是一个例外,Layout默认AnchorPoint是(0,0),并且默认是忽略AnchorPoint的值,也就是说,你设置了AnchorPoint也没实用。此时。须要使用Node的ignoreAnchorPointForPosition(false)方法来强制使用AnchorPoint。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844