如何在AndEngine中决定SVG精灵的宽度和高度

发布于 2024-12-23 16:33:44 字数 332 浏览 0 评论 0原文

我正在使用 AndEngine 加载 svg 图像作为我的 Sprites。

我遇到的问题是我无法弄清楚如何缩放图像以适应运行它的特定设备。

sprite= new Sprite(positionX, positionY, WIDTH,HEIGHT,TextureRegion);

它采用的参数是 x 和 y 坐标上的位置,然后是宽度和高度。

我遇到的问题是我无法弄清楚如何将精灵缩放到我想要的正确宽度和高度。

例如,我有一个标题,我希望标题在更大的设备上更大,我如何决定设备是否更大,并针对更大的屏幕放大它,针对更小的屏幕缩小标题?

I am using AndEngine to load a svg images as my Sprites.

The problem I am having with this is that i can't figure out how to scale the image to fit the particular device on which it is being run.

sprite= new Sprite(positionX, positionY, WIDTH,HEIGHT,TextureRegion);

The parameters that it takes are the position's on x and y coordinates, and then width, and height.

The problem I am having is that I can't figure out how to scale the sprite to the right width and height for how I want it.

For example I have a title, and I want the title to be bigger on bigger devices, how would I decide if the device is bigger and scale it up for a bigger screen and down for a smaller screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青巷忧颜 2024-12-30 16:33:44

如果您使用恒定的相机尺寸,则所有屏幕都会缩放(因此所有实体)。

确定一个恒定的大小,例如 720x480

final static int CAMERA_WIDTH = 720;
final static int CAMERA_HEIGHT = 480;

然后,在创建引擎选项时,使用:

... new EngineOptions(... new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), ...);

在每个设备上,相机将自行缩放以尽可能适合分辨率,同时保持宽度与宽度之间的比率。高度。
现在,在创建精灵时,只需执行以下操作:

Sprite sprite = new Sprite(x, y, TextureRegion);

不要指定精灵大小!它相对于相机尺寸的大小将根据纹理区域的大小来决定,并且它将是一个常数。 然后,它将被相机缩放为- 设备屏幕缩放,从一个设备到另一个设备会发生变化,但比例将保持不变 - 在分辨率与相机宽度/高度比不同的设备上,游戏不会看起来像糟糕的缩放图像。

我认为AndEngine提供了一个很好的方法来处理不同的屏幕分辨率;恕我直言,这是最好使用的。

If you use a constant camera size, all of the screen is scaled (Hence all of the entities).

Decide on a constant size, for exaple 720x480.

final static int CAMERA_WIDTH = 720;
final static int CAMERA_HEIGHT = 480;

Then, when creating the engine options, use:

... new EngineOptions(... new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), ...);

On each device, the camera will scale itself to fit the resolution as good possible, while keeping the ratio between width & height.
Now, when creating a sprite, just do:

Sprite sprite = new Sprite(x, y, TextureRegion);

Don't give the sprite size! Its size comparing to the camera size will be decided according to the texture region size, and it will be a constant one. Then, it will be scaled by the camera-to-device-screen scaling, which changes from one device to another, but the ratio will remain constant - the game will not look like a bad scaled image on devices with a different resoltuion that the camera width/height ratio.

I think that's a great method that AndEngine provides to deal with different screen resolution; IMHO, it is the best to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文