{"id":13395665,"url":"https://github.com/xaguzman/tween-engine-dart","last_synced_at":"2025-10-23T07:02:34.644Z","repository":{"id":13645268,"uuid":"16338712","full_name":"xaguzman/tween-engine-dart","owner":"xaguzman","description":"This is a dart port of the original java Universal Tween Engine created by Aurelien Ribbon","archived":false,"fork":false,"pushed_at":"2019-03-12T18:22:57.000Z","size":1427,"stargazers_count":33,"open_issues_count":2,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-07-31T18:15:44.780Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xaguzman.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-29T08:00:06.000Z","updated_at":"2022-09-13T11:12:12.000Z","dependencies_parsed_at":"2022-08-29T06:50:57.602Z","dependency_job_id":null,"html_url":"https://github.com/xaguzman/tween-engine-dart","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaguzman%2Ftween-engine-dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaguzman%2Ftween-engine-dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaguzman%2Ftween-engine-dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaguzman%2Ftween-engine-dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xaguzman","download_url":"https://codeload.github.com/xaguzman/tween-engine-dart/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243493069,"owners_count":20299594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:00:27.444Z","updated_at":"2025-10-23T07:02:34.540Z","avatar_url":"https://github.com/xaguzman.png","language":"Dart","funding_links":[],"categories":["Animation","Libraries","动画"],"sub_categories":["Animation"],"readme":"[![Build Status](https://travis-ci.org/xaguzman/tween-engine-dart.svg?branch=master)](https://travis-ci.org/xaguzman/tween-engine-dart)\n\nLicense\n=======\n\nApache License 2.0\n\n\nAbout\n=====\n\nThis is a dart port of the [original java Universal Tween Engine][1] created by Aurelien Ribbon.\nThis readme is an adaptation of the original's engine readme and includes how things are handled in the dart version of the engine.\n\nYou can find a demo of the library [here][2].\nThe engine might have some bugs. Use at your own risk.\n\n______\n\n\nIntroduction\n============\n\nThe Universal Tween Engine enables the interpolation of every attribute from any object in any dart project (server or client side).\nTweens are 'fire and forget'.   \n\nImplementing\n------------\n\nDart, unlike javascript, has no string accessors for objects, such as `myObject['myProperty']`.\nReflection methods are still under development in Dart, and they will be slow.\nSo, there are two ways of telling the engine which properties you want to tween.\nThe first one is very useful if you do not have control over the class you want to tween a property of.\nThe second one is a bit less verbose but requires code in the class you want to tween.\n\n\n### Using `TweenAccessor`\n\nCreate an accessor that implements the `TweenAccessor` interface,\nregister it to the engine, and animate anything you want!\n\n```dart\nclass MyAccessor implements TweenAccessor\u003cMyClass\u003e{\n  static const Type1 = 1;\n  \n  int getValues(MyClass target, Tween tween, int tweenType, List\u003cnum\u003e returnValues){\n    if ( tweenType == MyAccessor.Type1 ){\n      returnValues[0] = target.x;\n      returnValues[1] = target.y;\n      return 2;\n    }\n    return 0;\n  }\n\n  void setValues(MyClass target, Tween tween, int tweenType, List\u003cnum\u003e newValues){\n    if ( tweenType == MyAccessor.Type1 ){\n      target.x = newValues[0];\n      target.y = newValues[1];\n    }\n  }\n}\n\nclass MyClass{\n  num x=0, y=0;\n}\n\nmain(){\n   Tween.registerAccessor(MyClass, new MyAccessor());\n}\n\n```\n\n\n### Using `Tweenable`\n\nMake sure the class you want to tween implements the `Tweenable` interface.\n\n```dart\nclass MyTweenable implements Tweenable {\n  static const int ANSWER = 1;\n  static const int CIRCLE = 2;\n\n  int answer = 42;\n  num circle = 6.2831853;\n\n  /**\n   * Updates [returnValues] with the values of the properties you want to tween\n   * when you run a `tweenType` tween.\n   * Returns the number of values set in [returnValues].\n   */\n  int getTweenableValues(int tweenType, Tween tween, List\u003cnum\u003e returnValues) {\n    if (tweenType == ANSWER) {\n      returnValues[0] = answer;\n    } else if (tweenType == CIRCLE) {\n      returnValues[0] = circle;\n    }\n    return 1;\n  }\n\n  /**\n   * Updates this object's properties with values from [newValues],\n   * in the [tweenType] fashion of `getTweenableValues`.\n   */\n  void setTweenableValues(int tweenType, Tween tween, List\u003cnum\u003e newValues) {\n    if (tweenType == ANSWER) {\n      answer = newValues[0];\n    } else if (tweenType == CIRCLE) {\n      circle = newValues[0];\n    }\n  }\n}\n```\n\n\nUpdating\n--------\n\n_For the tween to be completed, a continuous call to your TweenManager's `.update(delta)` is needed.\nThe delta parameter represents the time elapsed in **milliseconds** since last call to `update`_.\n\nAn easy way to obtain the delta is the `window.animationFrame` method:\n\n```dart\n\nTweenManager myManager;\nmain(){\n  ...\n  myManager = new TweenManager();\n  window.animationFrame.then(update);\n}\n\nnum lastUpdate = 0;\nupdate(num delta){\n  num deltaTime = (delta - lastUpdate) / 1000;\n  lastUpdate = delta;\n  \n  myManager.update(deltaTime);\n  window.animationFrame.then(update);\n}\n```\n\nNext, send your objects to another position (here x=20 and y=30), with a smooth elastic transition, during 1 second.\n\n```dart\n// Arguments are \n// 1. the target\n// 2. the type of interpolation\n// 3. the duration in seconds\n// Additional methods specify the target values, and the easing function. \n\nmain(){\n  ...\n  Tween.to(myClass, MyAccessor.Type1, 1.0)\n    ..targetValues = [20, 30]\n    ..easing = Elastic.INOUT;\n  window.animationFrame.then(update);\n}\n\n```\n\n\nAPI\n---\n\nPossibilities are:\n\n```dart\nTween.to(...);   // interpolates from the current values to the targets\nTween.from(...); // interpolates from the given values to the current ones\nTween.set(...);  // apply the target values without animation (useful with a delay)\nTween.call(...); // calls a method (useful with a delay)\n```\n\nCurrent options are:\n\n```dart\nmyTween.delay = 0.5;\nmyTween.repeat(2, 0.5);\nmyTween.repeatYoyo(2, 0.5); \nmyTween.pause();\nmyTween.resume();\nmyTween.callback = callback;\nmyTween.callbackTriggers = flags;\nmyTween.userData = obj;\n```\n\nYou can of course chain everything (with dart's method cascading):\n\n```dart\nnew Tween.to(...)\n ..delay = 1\n ..repeat(2, 0.5)\n ..start(myManager);\n```\n\nBy altering the delta parameter, adding slow-motion, fast-motion or reverse play is easy,\nyou just need to change the speed of the update:\n\n```dart\nmyManager.update(delta * speed);\n```\n\nCreate some powerful animation sequences!\n\n```dart\nnew Timeline.sequence()\n    // First, set all objects to their initial positions\n    ..push(Tween.set(...))\n    ..push(Tween.set(...))\n    ..push(Tween.set(...))\n\n    // Wait 1s\n    ..pushPause(1.0)\n\n    // Move the objects around, one after the other\n    ..push(Tween.to(...))\n    ..push(Tween.to(...))\n    ..push(Tween.to(...))\n\n    // Then, move the objects around at the same time\n    ..beginParallel()\n        ..push(Tween.to(...))\n        ..push(Tween.to(...))\n        ..push(Tween.to(...))\n    ..end()\n\n    // And repeat the whole sequence 2 times\n    // with a 0.5s pause between each iteration\n    ..repeatYoyo(2, 0.5)\n\n    // Let's go!\n    ..start(myManager);\n```\n\nYou can also quickly create timers:\n\n```dart\nnew Tween.call(myCallback)\n  ..delay = 3000\n  ..start(myManager);\n```\n\n\nMain features\n=============\n\n- Supports every [interpolation function defined by Robert Penner](http://www.robertpenner.com/easing/).\n- Can be used with any object. You just have to implement the `TweenAccessor` interface when you want interpolation capacities.\n- Every attribute can be interpolated. The only requirement is that what you want to interpolate can be represented as a number.\n- One line is sufficient to create and start a simple interpolation.\n- Delays can be specified, to trigger the interpolation only after some time.\n- Many callbacks can be specified (when tweens complete, start, end, etc.).\n- Tweens and Timelines are pooled by default. If enabled, there won't be any object allocation during runtime!\n- Tweens can be sequenced when used in Timelines.\n- Tweens can act on more than one value at a time, so a single tween can change the whole position (X and Y) of a sprite for instance !\n- Tweens and Timelines can be repeated, with a yoyo style option.\n- Simple timers can be built with `Tween.callBack()`.\n- Source code extensively documented!\n- Test suite included!\n\n\nTesting suite\n=============\n\nSince `0.10.0`, tweenengine has a (crude) test suite.\nIt leverages the `unittest` package.\n\nTo run it, you'll either need _Dartium_ or _dart2js_.\n\nUsing Dartium\n-------------\n\nBrowse `test/test.html`.\n\nUsing dart2js\n-------------\n\nCompile `test/test.dart` to `test/test.dart.js` :\n\n```bash\n$ dart2js test/test.dart -v -o test/test.dart.js\n```\n\nThen, browse `test/test.html`.\n\n\n\n  [1]: https://code.google.com/p/java-universal-tween-engine/\n  [2]: http://xaguzman.github.io/tween-engine-dart/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaguzman%2Ftween-engine-dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxaguzman%2Ftween-engine-dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaguzman%2Ftween-engine-dart/lists"}