anim.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  5. <title>Module anim</title>
  6. <link rel="stylesheet" href="../luadoc.css" type="text/css" />
  7. <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo"></div>
  13. <div id="product_name"><big><b></b></big></div>
  14. <div id="product_description"></div>
  15. </div> <!-- id="product" -->
  16. <div id="main">
  17. <div id="navigation">
  18. <h1>Goo</h1>
  19. <ul>
  20. <li><a href="../index.html">Index</a></li>
  21. </ul>
  22. <!-- Module list -->
  23. <h1>Modules</h1>
  24. <ul>
  25. <li><strong>anim</strong></li>
  26. <li>
  27. <a href="../modules/goo.html">goo</a>
  28. </li>
  29. <li>
  30. <a href="../modules/goo.button.html">goo.button</a>
  31. </li>
  32. <li>
  33. <a href="../modules/goo.checkbox.html">goo.checkbox</a>
  34. </li>
  35. <li>
  36. <a href="../modules/goo.colorpick.html">goo.colorpick</a>
  37. </li>
  38. <li>
  39. <a href="../modules/goo.image.html">goo.image</a>
  40. </li>
  41. <li>
  42. <a href="../modules/goo.null.html">goo.null</a>
  43. </li>
  44. <li>
  45. <a href="../modules/goo.object.html">goo.object</a>
  46. </li>
  47. <li>
  48. <a href="../modules/goo.panel.html">goo.panel</a>
  49. </li>
  50. <li>
  51. <a href="../modules/goo.progressbar.html">goo.progressbar</a>
  52. </li>
  53. <li>
  54. <a href="../modules/goo.text.html">goo.text</a>
  55. </li>
  56. <li>
  57. <a href="../modules/goo.textinput.html">goo.textinput</a>
  58. </li>
  59. </ul>
  60. <!-- File list -->
  61. </div><!-- id="navigation" -->
  62. <div id="content">
  63. <h1>Module <code>anim</code></h1>
  64. <p>Animation library. <br/>This library gives you functions to animate a variable from one value to another. <br/>You can group and chain multiple animations, for instance grouping two animations that <br/>animate the x and y positions of an object. <br/>How anim interpolates between the two values are set by animation styles such as linear, quadIn etc. <br/>To load do the following. <pre class="example"> anim = require 'anim/anim'<br/> function love.update(dt)<br/> anim:update(dt)<br/> end </pre></p>
  65. <p><small><b>Release:</b> 2010-02-26 Version 1</small></p>
  66. <h2>Functions</h2>
  67. <table class="function_list">
  68. <tr>
  69. <td class="name" nowrap><a href="#anim.chain:new">anim.chain:new</a>&nbsp;(...)</td>
  70. <td class="summary">Creates an animation chain that plays multiple animations one after another.</td>
  71. </tr>
  72. <tr>
  73. <td class="name" nowrap><a href="#anim.chain:onFinish">anim.chain:onFinish</a>&nbsp;(...)</td>
  74. <td class="summary">Callback function when the last animation in the chain finishes </td>
  75. </tr>
  76. <tr>
  77. <td class="name" nowrap><a href="#anim.chain:pause">anim.chain:pause</a>&nbsp;()</td>
  78. <td class="summary">Pauses the animation chain </td>
  79. </tr>
  80. <tr>
  81. <td class="name" nowrap><a href="#anim.chain:play">anim.chain:play</a>&nbsp;()</td>
  82. <td class="summary">Plays/resumes the animation chain.</td>
  83. </tr>
  84. <tr>
  85. <td class="name" nowrap><a href="#anim.group:new">anim.group:new</a>&nbsp;(...)</td>
  86. <td class="summary">Creates an animation group which can hold individual animations.</td>
  87. </tr>
  88. <tr>
  89. <td class="name" nowrap><a href="#anim.group:onFinish">anim.group:onFinish</a>&nbsp;()</td>
  90. <td class="summary">Callback function when all the animations in the group have finished </td>
  91. </tr>
  92. <tr>
  93. <td class="name" nowrap><a href="#anim.group:pause">anim.group:pause</a>&nbsp;()</td>
  94. <td class="summary">Pauses all the animations in the group </td>
  95. </tr>
  96. <tr>
  97. <td class="name" nowrap><a href="#anim.group:play">anim.group:play</a>&nbsp;()</td>
  98. <td class="summary">Plays/resumes all the animations in the group together </td>
  99. </tr>
  100. <tr>
  101. <td class="name" nowrap><a href="#anim.group:reverse">anim.group:reverse</a>&nbsp;()</td>
  102. <td class="summary">Reverses all the animations in the group </td>
  103. </tr>
  104. <tr>
  105. <td class="name" nowrap><a href="#anim.group:setTime">anim.group:setTime</a>&nbsp;(time)</td>
  106. <td class="summary">Sets the time period of every animation in the group </td>
  107. </tr>
  108. <tr>
  109. <td class="name" nowrap><a href="#anim:easy">anim:easy</a>&nbsp;(table, key, start, finish, time, style)</td>
  110. <td class="summary">Convenience function for anim:new().</td>
  111. </tr>
  112. <tr>
  113. <td class="name" nowrap><a href="#anim:finish">anim:finish</a>&nbsp;()</td>
  114. <td class="summary">Finish the animation.</td>
  115. </tr>
  116. <tr>
  117. <td class="name" nowrap><a href="#anim:moveTo">anim:moveTo</a>&nbsp;(object, x, y, time, style, delay)</td>
  118. <td class="summary">Animates an object from it's current position to another.</td>
  119. </tr>
  120. <tr>
  121. <td class="name" nowrap><a href="#anim:new">anim:new</a>&nbsp;(anim_table)</td>
  122. <td class="summary">Create a new animation instance.</td>
  123. </tr>
  124. <tr>
  125. <td class="name" nowrap><a href="#anim:onFinish">anim:onFinish</a>&nbsp;()</td>
  126. <td class="summary">Callback function when the animation is finished.</td>
  127. </tr>
  128. <tr>
  129. <td class="name" nowrap><a href="#anim:onPause">anim:onPause</a>&nbsp;()</td>
  130. <td class="summary">Callback function when anim:pause() is called </td>
  131. </tr>
  132. <tr>
  133. <td class="name" nowrap><a href="#anim:onPlay">anim:onPlay</a>&nbsp;()</td>
  134. <td class="summary">Callback function when anim:play() is called </td>
  135. </tr>
  136. <tr>
  137. <td class="name" nowrap><a href="#anim:pause">anim:pause</a>&nbsp;()</td>
  138. <td class="summary">Pause the animation.</td>
  139. </tr>
  140. <tr>
  141. <td class="name" nowrap><a href="#anim:play">anim:play</a>&nbsp;()</td>
  142. <td class="summary">Plays or resumes the animation </td>
  143. </tr>
  144. <tr>
  145. <td class="name" nowrap><a href="#anim:reverse">anim:reverse</a>&nbsp;()</td>
  146. <td class="summary">Reverse the animation.</td>
  147. </tr>
  148. <tr>
  149. <td class="name" nowrap><a href="#anim:update">anim:update</a>&nbsp;(dt)</td>
  150. <td class="summary">Updates all animations, use inside love.update().</td>
  151. </tr>
  152. </table>
  153. <h2>Tables</h2>
  154. <table class="table_list">
  155. <tr>
  156. <td class="name" nowrap><a href="#anim_table">anim_table</a></td>
  157. <td class="summary">An animation table </td>
  158. </tr>
  159. <tr>
  160. <td class="name" nowrap><a href="#styles">styles</a></td>
  161. <td class="summary">List of animation styles you can use.</td>
  162. </tr>
  163. </table>
  164. <h2>Examples</h2>
  165. <table class="table_list">
  166. <tr>
  167. <td class="name" nowrap><a href="#Sliding text">Sliding text</a></td>
  168. <td class="summary">Animate text to slide in from offscreen.</td>
  169. </tr>
  170. </table>
  171. <br/>
  172. <br/>
  173. <h2><a name="functions"></a>Functions</h2>
  174. <dl class="function">
  175. <dt><a name="anim.chain:new"></a><span>anim.chain:</span><strong>new</strong>&nbsp;( ... )</dt>
  176. <dd>
  177. <p class="func_description">Creates an animation chain that plays multiple animations one after another.</p>
  178. <h3>Parameters</h3>
  179. <ul>
  180. <li>
  181. <b>...</b> <i><small></small></i><br/>a list of animations to chain, in order.
  182. </li>
  183. </ul>
  184. <h3>Return value:</h3>
  185. <p class="func_return">table: an animation chain.</p>
  186. </dd>
  187. <dt><a name="anim.chain:onFinish"></a><span>anim.chain:</span><strong>onFinish</strong>&nbsp;( ... )</dt>
  188. <dd>
  189. <p class="func_description">Callback function when the last animation in the chain finishes</p>
  190. </dd>
  191. <dt><a name="anim.chain:pause"></a><span>anim.chain:</span><strong>pause</strong>&nbsp;( )</dt>
  192. <dd>
  193. <p class="func_description">Pauses the animation chain</p>
  194. </dd>
  195. <dt><a name="anim.chain:play"></a><span>anim.chain:</span><strong>play</strong>&nbsp;( )</dt>
  196. <dd>
  197. <p class="func_description">Plays/resumes the animation chain.</p>
  198. </dd>
  199. <dt><a name="anim.group:new"></a><span>anim.group:</span><strong>new</strong>&nbsp;( ... )</dt>
  200. <dd>
  201. <p class="func_description">Creates an animation group which can hold individual animations.</p>
  202. <h3>Parameters</h3>
  203. <ul>
  204. <li>
  205. <b>...</b> <i><small></small></i><br/>multiple animations to group.
  206. </li>
  207. </ul>
  208. <h3>Return value:</h3>
  209. <p class="func_return">table: an animation group.</p>
  210. </dd>
  211. <dt><a name="anim.group:onFinish"></a><span>anim.group:</span><strong>onFinish</strong>&nbsp;( )</dt>
  212. <dd>
  213. <p class="func_description">Callback function when all the animations in the group have finished</p>
  214. </dd>
  215. <dt><a name="anim.group:pause"></a><span>anim.group:</span><strong>pause</strong>&nbsp;( )</dt>
  216. <dd>
  217. <p class="func_description">Pauses all the animations in the group</p>
  218. </dd>
  219. <dt><a name="anim.group:play"></a><span>anim.group:</span><strong>play</strong>&nbsp;( )</dt>
  220. <dd>
  221. <p class="func_description">Plays/resumes all the animations in the group together</p>
  222. </dd>
  223. <dt><a name="anim.group:reverse"></a><span>anim.group:</span><strong>reverse</strong>&nbsp;( )</dt>
  224. <dd>
  225. <p class="func_description">Reverses all the animations in the group</p>
  226. </dd>
  227. <dt><a name="anim.group:setTime"></a><span>anim.group:</span><strong>setTime</strong>&nbsp;( time )</dt>
  228. <dd>
  229. <p class="func_description">Sets the time period of every animation in the group</p>
  230. <h3>Parameters</h3>
  231. <ul>
  232. <li>
  233. <b>time</b> <i><small>:number</small></i><br/>time in seconds.
  234. </li>
  235. </ul>
  236. </dd>
  237. <dt><a name="anim:easy"></a><span>anim:</span><strong>easy</strong>&nbsp;( table, key, start, finish, time, style )</dt>
  238. <dd>
  239. <p class="func_description">Convenience function for anim:new(). Creates an animation instance. <br/>The animation will automatically play.</p>
  240. <h3>Parameters</h3>
  241. <ul>
  242. <li>
  243. <b>table</b> <i><small>:table</small></i><br/>The table holding the value you wish to animate.
  244. </li>
  245. <li>
  246. <b>key</b> <i><small>:string</small></i><br/>The key's value you wish to animate.
  247. </li>
  248. <li>
  249. <b>start</b> <i><small>:number</small></i><br/>The starting value.
  250. </li>
  251. <li>
  252. <b>finish</b> <i><small>:number</small></i><br/>The finishing value.
  253. </li>
  254. <li>
  255. <b>time</b> <i><small>:number</small></i><br/>The time it takes for the animation to complete. (In seconds)
  256. </li>
  257. <li>
  258. <b>style</b> <i><small>:string</small></i><br/>The style of the animation.
  259. </li>
  260. </ul>
  261. <h3>Return value:</h3>
  262. <p class="func_return">table: An animation instance.</p>
  263. <h3>See also:</h3>
  264. <ul>
  265. <li><a href="../modules/anim.html#styles">
  266. styles
  267. </a>
  268. <li><a href="../modules/anim.html#anim_table">
  269. anim_table
  270. </a>
  271. <li><a href="">
  272. anim:new
  273. </a>
  274. </ul>
  275. </dd>
  276. <dt><a name="anim:finish"></a><span>anim:</span><strong>finish</strong>&nbsp;( )</dt>
  277. <dd>
  278. <p class="func_description">Finish the animation. (Instantaneus)</p>
  279. </dd>
  280. <dt><a name="anim:moveTo"></a><span>anim:</span><strong>moveTo</strong>&nbsp;( object, x, y, time, style, delay )</dt>
  281. <dd>
  282. <p class="func_description">Animates an object from it's current position to another. <br/>The object must have x and y keys! <br/>The animation will automatically play.</p>
  283. <h3>Parameters</h3>
  284. <ul>
  285. <li>
  286. <b>object</b> <i><small>:table</small></i><br/>An object with 'x' and 'y' keys.
  287. </li>
  288. <li>
  289. <b>x</b> <i><small>:number</small></i><br/>The target x position.
  290. </li>
  291. <li>
  292. <b>y</b> <i><small>:number</small></i><br/>The target y position.
  293. </li>
  294. <li>
  295. <b>time</b> <i><small>:number</small></i><br/>The time it takes for the animation to complete. (In seconds)
  296. </li>
  297. <li>
  298. <b>style</b> <i><small>:string</small></i><br/>The style of the animation.
  299. </li>
  300. <li>
  301. <b>delay</b> <i><small>:number</small></i><br/>The time it waits before starting the animation. (In seconds)
  302. </li>
  303. </ul>
  304. <h3>Return value:</h3>
  305. <p class="func_return">table: An animation instance.</p>
  306. <h3>See also:</h3>
  307. <ul>
  308. <li><a href="../modules/anim.html#anim_table">
  309. anim_table
  310. </a>
  311. <li><a href="../modules/anim.html#styles">
  312. styles
  313. </a>
  314. </ul>
  315. </dd>
  316. <dt><a name="anim:new"></a><span>anim:</span><strong>new</strong>&nbsp;( anim_table )</dt>
  317. <dd>
  318. <p class="func_description">Create a new animation instance.</p>
  319. <h3>Parameters</h3>
  320. <ul>
  321. <li>
  322. <b>anim_table</b> <i><small></small></i><br/>A table of animation paremeters.
  323. </li>
  324. </ul>
  325. <h3>Usage:</h3>
  326. <pre class="example"> new_animation = anim:new{<br /> table = myTable,<br /> key = 'x_position',<br /> start = 12,<br /> finish = 120,<br /> time = 4,<br /> style = 'linear'<br /> }<br /> </pre><br />
  327. <h3>Return value:</h3>
  328. <p class="func_return">table: An animation instance you can call anim methods on.</p>
  329. <h3>See also:</h3>
  330. <ul>
  331. <li><a href="../modules/anim.html#anim_table">
  332. anim_table
  333. </a>
  334. <li><a href="../modules/anim.html#Sliding text">
  335. Sliding text
  336. </a>
  337. </ul>
  338. </dd>
  339. <dt><a name="anim:onFinish"></a><span>anim:</span><strong>onFinish</strong>&nbsp;( )</dt>
  340. <dd>
  341. <p class="func_description">Callback function when the animation is finished.</p>
  342. <h3>Usage:</h3>
  343. <pre class="example"> new_anim = anim:new( anim_table )<br /> function new_anim:onFinish()<br /> print('animation finished')<br /> end<br /> </pre><br />
  344. </dd>
  345. <dt><a name="anim:onPause"></a><span>anim:</span><strong>onPause</strong>&nbsp;( )</dt>
  346. <dd>
  347. <p class="func_description">Callback function when anim:pause() is called</p>
  348. <h3>See also:</h3>
  349. <ul>
  350. <li><a href="">
  351. anim:onFinish
  352. </a>
  353. </ul>
  354. </dd>
  355. <dt><a name="anim:onPlay"></a><span>anim:</span><strong>onPlay</strong>&nbsp;( )</dt>
  356. <dd>
  357. <p class="func_description">Callback function when anim:play() is called</p>
  358. <h3>See also:</h3>
  359. <ul>
  360. <li><a href="">
  361. anim:onFinish
  362. </a>
  363. </ul>
  364. </dd>
  365. <dt><a name="anim:pause"></a><span>anim:</span><strong>pause</strong>&nbsp;( )</dt>
  366. <dd>
  367. <p class="func_description">Pause the animation.</p>
  368. </dd>
  369. <dt><a name="anim:play"></a><span>anim:</span><strong>play</strong>&nbsp;( )</dt>
  370. <dd>
  371. <p class="func_description">Plays or resumes the animation</p>
  372. </dd>
  373. <dt><a name="anim:reverse"></a><span>anim:</span><strong>reverse</strong>&nbsp;( )</dt>
  374. <dd>
  375. <p class="func_description">Reverse the animation.</p>
  376. </dd>
  377. <dt><a name="anim:update"></a><span>anim:</span><strong>update</strong>&nbsp;( dt )</dt>
  378. <dd>
  379. <p class="func_description">Updates all animations, use inside love.update().</p>
  380. <h3>Parameters</h3>
  381. <ul>
  382. <li>
  383. <b>dt</b> <i><small>:number</small></i><br/>delta time
  384. </li>
  385. </ul>
  386. </dd>
  387. </dl>
  388. <h2><a name="tables"></a>Tables</h2>
  389. <dl class="table">
  390. <dt><a name="anim_table"></a><strong>anim_table</strong></dt>
  391. <dd>An animation table
  392. <em>Fields</em>
  393. <ul>
  394. <li>
  395. <b>table</b> The table to pass to the anim object
  396. </li>
  397. <li>
  398. <b>key</b> The key to animate. (table[key] will be animated).
  399. </li>
  400. <li>
  401. <b>start</b> The value the animation starts at. (if nil current table[key] value will be used).
  402. </li>
  403. <li>
  404. <b>finish</b> The value the animation finishes at. (if nil current table[key] value will be used).
  405. </li>
  406. <li>
  407. <b>time</b> The time it takes for the animation to complete. (in seconds, default 1).
  408. </li>
  409. <li>
  410. <b>delay</b> The time it takes for the animation to start after calling anim:play(). (in seconds, default 0).
  411. </li>
  412. <li>
  413. <b>style</b> The style of the animation. (a string, default 'linear'). <a href='#styles'>See style</a>.
  414. </li>
  415. <li>
  416. <b>styleargs</b> Some styles such as 'elastic' can take extra parameters in the form of a table {arg1,arg2}.
  417. </li>
  418. </ul>
  419. </dd>
  420. <dt><a name="styles"></a><strong>styles</strong></dt>
  421. <dd>List of animation styles you can use.
  422. <em>Fields</em>
  423. <ul>
  424. <li>
  425. <b>linear</b>
  426. </li>
  427. <li>
  428. <b>quartIn</b>
  429. </li>
  430. <li>
  431. <b>quartOut</b>
  432. </li>
  433. <li>
  434. <b>quartInOut</b>
  435. </li>
  436. <li>
  437. <b>quadIn</b>
  438. </li>
  439. <li>
  440. <b>quadOut</b>
  441. </li>
  442. <li>
  443. <b>quadInOut</b>
  444. </li>
  445. <li>
  446. <b>expoIn</b>
  447. </li>
  448. <li>
  449. <b>expoOut</b>
  450. </li>
  451. <li>
  452. <b>expoInOut</b>
  453. </li>
  454. <li>
  455. <b>elastic</b>
  456. </li>
  457. </ul>
  458. </dd>
  459. </dl>
  460. <h2><a name="examples"></a>Examples</h2>
  461. <dl class="example">
  462. <dt><a name="Sliding text"></a><strong>Sliding text</strong></dt>
  463. <dd>
  464. <div class="example">
  465. Here's how: <pre class="example"><br /> anim = require 'anim/anim'<br /> <br /> function love.load()<br /> text = { x = -100, str = 'Woo!' }<br /> new_anim = anim:new{<br /> table = text,<br /> key = 'x',<br /> start = -100<br /> finish = 100,<br /> time = 2,<br /> style = 'quadInOut'<br /> }<br /> new_anim:play()<br /> end<br /> <br /> function love.update(dt)<br /> anim:update(dt)<br /> end<br /> <br /> function love.draw()<br /> love.graphics.print(text.str, text.x, 100)<br /> end<br /> </pre><br />
  466. </div>
  467. </dd>
  468. </dl>
  469. </div> <!-- id="content" -->
  470. </div> <!-- id="main" -->
  471. <div id="about">
  472. <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
  473. </div> <!-- id="about" -->
  474. </div> <!-- id="container" -->
  475. </body>
  476. </html>