Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add aspect ratio to particle system #5666

Conversation

@Marssssssss
Copy link
Contributor

Marssssssss commented Nov 4, 2019

re: forum.cocos.org/t/topic/74021

主要改动:
        在 particleSystem 内新添 aspectRatio 变量,默认为 1。该变量会参与到 particle-simulator 中粒子顶点相关的运算来让每个粒子的宽高比保持和纹理一致。用户也可以通过更改其值在脚本中动态地自定义其宽高拉伸比例。

宽高比 aspectRatio 和尺寸 size 之间的关系:
        当 aspectRatio > 1 时,保持宽度为 size,缩短高度为 size / aspectRatio;当 aspectRatio < 1 时,保持高度为 size, 缩短宽度为 aspectRatio * size。这样可以保证宽和高二者中最大值为 size,视觉上相对合理。

解决的问题:
        论坛中用户在引入宽高比不一致的粒子图像的时候,由于之前的粒子尺寸固定为宽高都是 size,所以虽然纹理的宽高不一样,但在具体粒子表现的时候就会被拉伸到正方形。这里的改动主要是让用户导入的纹理在引擎中能够正常地表现出其原本具有的宽高比以防止拉伸,同时若用户需要拉伸只需更改此值而不用去改动资源。

@holycanvas holycanvas requested review from caryliu1999 and jareguo Nov 5, 2019
@holycanvas

This comment has been minimized.

Copy link
Contributor

holycanvas commented Nov 5, 2019

用户也可以通过更改其值在脚本中动态地自定义其宽高拉伸比例。

只能动态改么?不能在编辑器中设置么

@holycanvas

This comment has been minimized.

Copy link
Contributor

holycanvas commented Nov 5, 2019

原生平台也要加吧

@Marssssssss

This comment has been minimized.

Copy link
Contributor Author

Marssssssss commented Nov 6, 2019

原生平台也要加吧

原生那块也要加的。
目前只能动态改,因为加入这个属性的定义后编辑器没有出现这个属性的设置项。

* @property {Number} aspectRatio
* @default 1
*/
aspectRatio: 1,

This comment has been minimized.

Copy link
@jareguo

jareguo Nov 7, 2019

Contributor

不能作为布尔值吗?对用户来说不太关心具体宽高比是多少,他们只关心是否和原图宽高比一致

This comment has been minimized.

Copy link
@Marssssssss

Marssssssss Nov 7, 2019

Author Contributor

这里主要是考虑用户可能会想更改 aspect ratio 来实现某些类似扁平化的效果,可能会有更大的自定义空间

This comment has been minimized.

Copy link
@jareguo

jareguo Nov 7, 2019

Contributor

感觉好像没太必要?这样的话用户每次换图片都得重新算这个参数?

This comment has been minimized.

Copy link
@Marssssssss

Marssssssss Nov 11, 2019

Author Contributor

引擎会自动计算这个参数的,每次更换贴图以后都会自动去适配宽高比。这里是说用户可以自己改宽高比来实现拉伸,而默认的宽高比是会在每次加载 texture 之后去适配的。

This comment has been minimized.

Copy link
@Marssssssss

Marssssssss Nov 11, 2019

Author Contributor

unity3D 里面也是可以自定义粒子尺寸的。

@cocos-robot cocos-robot changed the base branch from v2.2.2 to v2.3.0 Nov 28, 2019
Copy link
Contributor

cocos-robot left a comment

@Marssssssss, v2.2.2 branch will be deleted, so we edited the base branch to v2.3.0, or this PR will be killed by GitHub.
Please review the commits history to ensure that the PR does not polluted by unneeded commits from your origin branch.
If you need to merge to other branch, you can first click the Edit button on the right side of the PR title, then switch the base branch.
If necessary, welcome to resubmit a new PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.