移动简笔画、锚点、动画或其他东西……? [英] Moving a Stick figure, anchorpoints, animation, or something else...?

查看:19
本文介绍了移动简笔画、锚点、动画或其他东西……?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我正在目标 c 中使用 cocos2d 制作一个带有简笔画的游戏...需要对不同的事物进行动画处理,所以请给我一个建议,告诉我什么是完成这些事物的运动的最佳方式:

Ok so I am making a game with stick figures with cocos2d in objective c... Different things need to be animated so please, give me a suggestion of what would be the best way to go about accomplishing the movement for these things:

  1. 主角-他是左下角的弓箭手,他不会四处走动,只是他会移动上半身,因为你需要改变你射击的角度……

  1. The main character- he is an archer in the bottom left corner who does not move around, except he will move his upper body because you need to change the angle of where you are shooting the angle...

敌人 - 成群结队向你冲来的简笔画人物,它们具有碰撞检测功能,并在被箭头精灵射中时死亡.

The enemies- hordes of stick figures coming at you that have collision detection and die when shot by an arrow sprite.

我应该如何让 1 和 2 移动?我应该掌握锚点并使用它们吗?(我真的很讨厌愚蠢的锚点,它们很难开始工作......但如果它们更好,我会使用它们)或者制作大量动画,或者有另一种更简单的方法将许多精灵组合成一个动作?

How should I make 1 and 2 move? should I master anchor points and use those? (I really hate stupid anchorpoints they are so hard to get to work... but I'll use these if they are better) or make tons of animations, or is there another simpler way to combine many sprites into a single movement?

推荐答案

我的一般建议:永远不要修改默认的锚点(0.5f,0.5f),除非你非常了解它的作用以及它的帮助你完成事情.在所有其他情况下,修改 position 属性.

My general advice: never, ever modify the default anchorPoint (0.5f, 0.5f) unless you have a really good understanding of what it does and how it helps you accomplish things. In all other cases, modify the position property.

特别是如果您进行基于边界框或半径的碰撞检测,修改锚点会适得其反.

Especially if you do bounding box or radius based collision detection, modifying the anchor point is counter-productive.

假设您的矩形精灵图像使用默认锚点,该锚点位于纹理的中心:

Let's assume your rectangular sprite image uses a default anchor point, which is in the center of the texture:

._______.
|       |
|       |
|   *   |
|       |
|       |
°-------°

* 标记纹理的锚点.如果将此精灵放置在 (250, 100) 位置,则精灵的锚点将位于坐标 (250, 100).

The * marks the anchorPoint of the texture. If you place this sprite at position (250, 100) then the sprite's anchorPoint will be at the coordinates (250, 100).

假设您将锚点移动到 (0.1f, 0.1f):

Let's say you move the anchorPoint to (0.1f, 0.1f):

  ._______.
  |       |
. |     . |
  |       |
  |       |
  | *     |
  °-------°

°       ° 

精灵的位置在 (250, 100) 处保持不变.锚点位置也不会改变.改变的是纹理如何以该点为中心.您可以通过查看浮动点来查看修改锚点之前的先前图像位置.实际上,您通过修改anchorPoint 所做的就是移动(偏移)节点纹理相对于节点位置的绘制位置.

The position of the sprite remains unchanged at (250, 100). The anchorPoint position also doesn't change. What changes is how the texture is centered around that point. You can see the previous image position before modifying the anchor point by looking at the floating dots. In effect, all you do by modifying the anchorPoint is to move (offset) where the node's texture is drawn relative to the node's position.

在上述情况下,纹理现在居中,其左下角位于节点位置上方.您不能再依赖精灵的位置来标记精灵图像的中心.如果您为游戏中的每个节点任意修改锚点,则节点的视觉表示与其位置之间不再有任何关联.因此,修改游戏对象的锚点是糟糕的设计.

In the above case the texture is now centered with its lower-left corner over the node's position. You can no longer rely on the position of the sprite marking the center of the sprite image. If you modify the anchorPoint arbitrarily for every node in the game, you no longer have any correlation between the visual representation of a node and its position. Thus it is bad design to modify the anchorPoint for gameplay objects.

此外,旋转或缩放将始终以锚点为中心.在旋转或缩放节点时,修改锚点可能会导致不良行为.

Furthermore, rotation or scaling will always be centered on the anchorPoint. Modifying the anchorPoint can result in undesirable behavior when rotating or scaling nodes.

让我们假设一个奇怪的、最坏的但完全可能的情况,即锚点不再位于纹理内:

Let's assume an odd, worst case, but entirely possible scenario where the anchorPoint is no longer inside the texture:

                     ._______.
                     |       |
                     |       |
                     |       |
  *                  |       |
                     |       |
                     °-------°

这意味着该精灵的位置偏移到实际图像显示位置的左侧.这可能导致碰撞检查差异,特别是上述情况将完全使基于半径的碰撞检查无效.在开发过程中,这也是一个令人困惑的情况.

That means the position of that sprite is offset far to the left of where the actual image is being displayed. This can lead to collision check discrepancies, in particular the above situation would entirely void radius-based collision checks. This is also a confusing situation to be in during development.

如果您可以确定精灵的位置始终位于其纹理的中心,而不是在没有调试绘图的帮助下甚至无法看到的任意点,您的游戏将更容易开发.

Your game will be far easier to develop if you can be sure that a sprite's position is always in the center of its texture, rather than some arbitrary point that you can't even see without the help of some debug drawing.

问题依然存在:

您希望何时修改锚点?

我只在以下情况下这样做,在所有其他情况下都避免这样做:

I've done so only in the following situations, and avoid it in all other scenarios:

  1. 将非动画纹理与屏幕/窗口边框或类似物对齐
  2. 右/左/上/下对齐标签、按钮或图像
  3. 在不修改节点位置的情况下对齐修改后的图像(即艺术家更新).

1) 很容易解释.假设您有一个全屏背景图像.要使其覆盖整个屏幕,您可以执行以下两种操作之一:

1) Is easy to explain. Assume you have a full-screen background image. To make it cover the entire screen, you can do one of two things:

  • 将位置更改为:(屏幕宽度/2,屏幕高度/2)
  • 将锚点更改为 (0, 0) 即 CGPointZero

你可以想象后者更容易做到.如果您永远不会移动背景,那很好.但是对于滚动背景,我不会更改锚点.

You can imagine the latter is easier to do. If you'll never move the background, it's fine doing that. However for a scrolling background I wouldn't change the anchorPoint.

2) 假设您的菜单系统要求各种按钮和图像与屏幕的右边框完全右对齐.所有按钮和图像的宽度都不同:即玩游戏、积分、设置、更酷的游戏!

2) Assume your menu system calls for various buttons and images to be right-aligned exactly with the right border of the screen. All buttons and images differ in width: ie Play Game, Credits, Settings, More Cool Games!

与其计算每个图像/按钮的单独位置,更容易通过将 anchorPoint 修改为 (1.0f, 0.5f) 来简单地右对齐它们,然后将图像/按钮精确定位在屏幕宽度 (和可变屏幕高度):位置=(屏幕宽度,100).

Instead of figuring out the individual positions for each image/button, it is easier to simply right-align them by modifying the anchorPoint to (1.0f, 0.5f) and then position the images/buttons at exactly the screen width (and variable screen height): position = (screen width, 100).

假设下图的位置在(屏幕宽度,屏幕高度/2),默认锚点(0.5f,0.5f).您可以看到图像的右半部分在屏幕区域之外:

Let's assume the following image's position is at (screen width, screen height / 2) with a default anchorPoint (0.5f, 0.5f). You can see the right half of the image is outside the screen area:

__________.
          |
      .___|___.
      |   |   |
      |   |   |
      |   *   |
      |   |   |
      |   |   |
      °---|---°
          |
----------°

使用修改的 (1.0f, 0.5f) 的锚点,图像可以与右侧屏幕/窗口边框整齐地右对齐,而不管其纹理的宽度如何.位置保持不变:(屏幕宽度,屏幕高度/2).

With a modified anchorPoint of (1.0f, 0.5f) the image can be neatly right-aligned with the right screen/window border, regardless of the width of its texture. The position remains the same: (screen width, screen height / 2).

__________.
          |
  ._______.
  |       |
  |       |
  |       *
  |       |
  |       |
  °-------°
          |
----------°

为了比较,如果你想在不修改锚点的情况下右对齐这个图像、菜单按钮或标签,你必须根据这个公式来设置它的位置:

Just for comparison, if you wanted to right-align this image, menu button, or label without modifying the anchorPoint, you would have to set its position according to this formula:

(screen width - contentSize.width * anchorPoint.x, screen height / 2)

公式仍然很简单,但是如果节点的 contentSize 发生变化,这将成为一件苦差事,这通常是标签的情况,例如分数从 1 位开始,但随着时间的推移增加到 2、3 和 4 位.在这种情况下,通过修改 anchorPoint 来右对齐节点是合理的,因为它避免了每次节点的 contentSize 发生变化时都必须重新计算位置.

The formula is still pretty simple, it becomes a chore however if the contentSize of the node changes, which is often the case for labels, for example the score starts with 1 digit but increases to 2, 3 and 4 digits over time. In such cases right-aligning a node by modifying the anchorPoint is justified because it avoids having to recalculate the position every time the contentSize of the node changes.

3) 在极少数情况下,艺术家向我提供了游戏对象的更新图像.图像大小发生了变化,因此它不再自然地融入游戏的图形.另一方面,对象的位置已经通过游戏测试确定,不应更改以避免重新测试游戏.

3) There are rare cases where an artist provided me with an updated image of a game object. The image size has changed, so it no longer fits naturally into the game's graphics. On the other hand, the object's position has already been well established through gameplay testing and should not be changed to avoid re-testing the game.

在这种情况下,需要调整 anchorPoint 以使新图像与其他图形很好地对齐,而不影响游戏玩法.这是一个安全的、最后一刻的修改.不要在生产阶段开始这样做,否则您将在项目的整个生命周期中陷入锚点调整地狱.不要去那里!

In such a case tweaking the anchorPoint so that the new image aligns well with the other graphics, without affecting the gameplay, is warranted. This is a safe, last-minute modification. Don't start doing this during the production phase or you'll end up in anchorPoint-tweaking-hell throughout the lifetime of your project. Don't go there!

总结:

只有在更容易将节点与其他节点或屏幕/窗口边框对齐,或者在不影响游戏玩法的情况下微调最终艺术的情况下,才修改 anchorPoint.

Modify anchorPoint only if that makes it easier to align nodes with other nodes or a screen/window border, or to fine-tune final art without affecting gameplay.

在所有其他情况下,仅使用位置来移动节点.

这篇关于移动简笔画、锚点、动画或其他东西……?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆