Advertisement
inmortalkaktus

Untitled

Apr 7th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. To start, I will explain how to scale a sprite (magnify and decrease). First, we need to know what parameters the definition has.
  2.  
  3. [CODE]#define AFFINEANIMCMD_FRAME(_xScale, _yScale, _rotation, _duration)[/CODE]
  4.  
  5. The X and Y scale, the rotation, and the duration.
  6.  
  7. We have to know that as higher "_xScale" and "_yScale", more fast will scale our sprite, This is not the size that will be scaled. If we use a positive value as "16", the scale will be a magnify, if we use a negative one, as "-32", the scale will be of reduction.
  8.  
  9. We have to know that the value of scale, and the duration are strictly linked, and I've bothered to take out the formula.
  10.  
  11. First, I will shorten the variables to make the formula more comfortable (although it is very simple).
  12.  
  13. [CODE]d = _duration
  14. x = _xScale
  15. k[/CODE]
  16.  
  17. [I]d[/I] will be the value of [I]_duration[/I], [I]x[/I] will be the value of [I]_xScale[/I] (or [I]_yScale[/I], is the same), and finally, [I]k[/I] will be the scale which we will give to the sprite. For example, if we want the sprite to be twice as large, k = 2. if we want the sprite to be 2/3 of the original, k = 2/3 (although I do not recommend this value much, the scale will not be too homogeneous)
  18.  
  19. Once we know that, let's see the formula (that you can clear to know the value that most interests you, or you can give values directly to know the duration)
  20.  
  21. [CENTER][IMG]https://i.imgur.com/YTTzNVy.png[/IMG][/CENTER]
  22.  
  23. [COLOR=#F72F2F][B]LOOK OUT!.-[/B][/COLOR] If the result of the formula gives you a value with decimals, I recommend that you choose to use other values that give a similar visual result, but not decimals, since the floats will not be processed. You can play with the scale speed.
  24.  
  25. [COLOR=#F72F2F][B]LOOK OUT! (2).-[/B][/COLOR] I will use the formula that you will see below, because I will work with a sprite that by default, is loaded with a size of 1x1 pixel, and there is a certain variation in the formula so that it can be scaled to its natural size, specifically the one below. But if you load the sprite directly with its original size, you have to use the previous one. Once you have applied this formula to scale it to its original size, you can apply the previous formula.
  26.  
  27. [CENTER][IMG]https://i.imgur.com/Gd8Brp7.png[/IMG][/CENTER]
  28.  
  29. Right, now, before use AFFINEANIM, we have to know that we must use this before every new AffineAnimCmd function (at least to me without this, it does not work):
  30.  
  31. [CODE]AFFINEANIMCMD_FRAME(_xScale, _yScale, 0, 0),[/CODE]
  32.  
  33. And later, We write the transformation we want to do.
  34.  
  35. For example, let's say that we have made the sprite load with dimensions of 1x1, and what we want to do is increase its size to the original, well we want that k = 1, a speed in x and y of about 16 (by default), so, let's calculate the necessary duration:
  36.  
  37. d = (240/16)*1 = 15
  38.  
  39. Right, so, now that we have all the parameters, let's write the necessary affineanims.
  40.  
  41. [CODE]static const union AffineAnimCmd gSpriteAffineAnim_85B1EA0[] =
  42. {
  43. AFFINEANIMCMD_FRAME(16, 16, 0, 0),
  44. AFFINEANIMCMD_FRAME(16, 16, 0, 15),
  45. AFFINEANIMCMD_END,
  46. };[/CODE]
  47.  
  48. And the result will be:
  49.  
  50. [CENTER][IMG]https://i.imgur.com/WLenoDu.gif[/IMG][/CENTER]
  51.  
  52. [QUOTE]But Inmortal, you did not modify anything, that was already like that.[/QUOTE]
  53.  
  54. Okay, so, let's try to reduce it by half.
  55.  
  56. Now, we want that k = 1/2, and [I]X [/I]e [I]Y[/I] = 16, so...
  57.  
  58. d = (240/16) * 1/2 = 7.5
  59.  
  60. Oops... We obtained a result that we do not want, it have decimals, so... What we can do?
  61.  
  62. Easy, reduce the speed ([I]_xScale[/I] and [I]_yScale[/I]) by half, that is the needed to augment [I]d[/I], because they are inversely proportional
  63.  
  64. We have that k = 1/2 and x = 8...
  65.  
  66. d = (240/8) * 1/2 = 15
  67.  
  68. Nice! We have an integer value, Now, let's adapt parameters:
  69.  
  70. [CODE]static const union AffineAnimCmd gSpriteAffineAnim_85B1EA0[] =
  71. {
  72. AFFINEANIMCMD_FRAME(8, 8, 0, 0),
  73. AFFINEANIMCMD_FRAME(8, 8, 0, 15),
  74. AFFINEANIMCMD_END,
  75. };[/CODE]
  76.  
  77. [CENTER][IMG]https://i.imgur.com/rwJ53Qi.gif[/IMG][/CENTER]
  78.  
  79. Analogously to magnify it.
  80.  
  81. To rotate it, we have to know that a value of 4, is proportional to a 90ΒΊ turn, and therefore, 16, is proportional to a complete turn.
  82.  
  83. Clarify that you will also use positive or negative values to choose the direction of rotation (positive, counter-clock wise, negative, clockwise)
  84.  
  85. Well, I will leave you a little sequence as an "exercise" so you can try to think what will happen:
  86.  
  87. [CODE] AFFINEANIMCMD_FRAME(16, 16, 0, 0),
  88. AFFINEANIMCMD_FRAME(16, 16, 0, 15),
  89. AFFINEANIMCMD_FRAME(16, 16, 0, 16),
  90. AFFINEANIMCMD_FRAME(-16, -16, -4, 16),
  91. AFFINEANIMCMD_END,[/CODE]
  92.  
  93. [SPOILER][CENTER][IMG]https://i.imgur.com/trYLn41.gif[/IMG][/CENTER][/SPOILER]
  94.  
  95. And that is all, I think I have covered in a pretty decent way how animations work in pokeemerald.
  96.  
  97. Good luck, and comment any question :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement