playif / play_phaser

A Dart port for Phaser 2D game engine.
MIT License
72 stars 13 forks source link

Use tween engine for tweens #1

Closed xaguzman closed 9 years ago

xaguzman commented 9 years ago

A bit of self promotion here, but I would love to see the tween engine put to use in a project like this:

https://github.com/xaguzman/tween-engine-dart

would you be up for adding it?

playif commented 9 years ago

Hi @xaguzman Thanks for your recommendation. It may be helpful to deal with the Phaser Tween System! I need to investigate how to cooperate with the Universal Tween Engine in Phaser Tween System.

xaguzman commented 9 years ago

I am all up for helping, although I am not very familiar with phaser. Let me know if there's anything I can do to help


Xavier Guzman

https://plus.google.com/u/0/+XavierGuzmanMX/posts/p/pub http://www.linkedin.com/profile/view?id=44608085 https://www.facebook.com/xavguz

On Mon, Aug 4, 2014 at 7:09 PM, playif notifications@github.com wrote:

Thanks for your recommendation. It may be helpful to deal with the Phaser Tween System! I need to investigate how to cooperate with the Universal Tween Engine in Phaser Tween System.

— Reply to this email directly or view it on GitHub https://github.com/playif/play_phaser/issues/1#issuecomment-51134591.

playif commented 9 years ago

I just looked your Tween Engine, The major problem is that Phaser targets easy and fun to write games. They made a lot of handy functions to let users quickly finish their prototype game.

However, your approach of Tween needs users to announce a field before using it.

In fact, some of functions in Phaser force me to use Mirror API, such as a Group class has a function setAll(String field, value).

As is well-known, using Mirror API results in low performance and bloated JS code. If I use your approach in my dart Phaser, it should be more reasonable to remove all usage of mirror API.

Maybe I can define several built-in field names, like Phaser.Field.x, Phaser.Field.alpha, Phaser.Field.rotation etc. to mitigate the coding efforts of using dart Phaser without Mirror API.

Any suggestion?

xaguzman commented 9 years ago

Does phaser tweening work on any objects made by the users? Or does it only work on phaser's own objects.

you could always have a TweenManager ( the one from the universal tween engine) stored somewhere, and then let them call RegisterTween( Tween). They can build their own tweens by using the static methods in Tween class.

would that solve the problem?

xaguzman commented 9 years ago

I just took a look at this link to get a grasp of how it works:

http://svejkgames.com/blog/post/how-to-use-tweens-in-phaser-framework/

phaser tweens should be quite straight forwards to migrate to the tween engine.

They seem to only tween on known objects. According to the example in the link, you should be able to implement Tweenable interface on the Sprite class, defining all kind of tweens you need, and then allowing the user to just use their sprite object for tweens.

Did that make sense?

playif commented 9 years ago

Great, although tween on every field would be cool, it may not practical in real cases. In fact, only a few fields need to use tweens (x, y,rotation,alpha in sprites, and rgb in colors). I will try adding Tween engine in my dart Phaser, thanks!

playif commented 9 years ago

Hi @xaguzman I tried to use Tween engine in the dart Phaser. I have some problems need to be solved:

  1. Is it possible to register only by the accessor with a parent class and work for all successor. For example: class Fields implements TweenAccessor{ ... } and Tween.registerAccessor(GameObject, new Fields());

All class (sprite, text, etc.) inherited from GameObject should work since they will have the right properties for tween.

  1. TweenPath is only for waypoints? Is it possible to use CatmullRom between two common tweens? Phaser may be able to do that..
  2. Is it possible to use getValue rather than getValues for saving memory when implement TweenAccessor? I'll use only single value each time, and use timeline to implement field set combination.
  3. Why don't you just use CallbackHandler as the parameter of Tween.callBack?
playif commented 9 years ago

I found target object may flick when using timeline connect two tweens.

The problem may be caused by using one time repeatYoyo on a timeline, which is a sequence timeline containing parallel timelines.

you can check my implementation on https://github.com/playif/play_phaser/blob/master/lib/tween/tween.dart

and usage on https://github.com/playif/play_phaser/blob/master/example/tweens/tweens_01_chained_tweens.dart

xaguzman commented 9 years ago
  1. Is it possible to register only by the accessor with a parent class and work for all successor. For example: class Fields implements TweenAccessor{ ... } and Tween.registerAccessor(GameObject, new Fields());

All class (sprite, text, etc.) inherited from GameObject should work since they will have the right properties for tween.

Right now this is not possible through TweenAccessors, I have certain confidence tho, that this should work on Tweenables

  1. TweenPath is only for waypoints? Is it possible to use CatmullRom between two common tweens? Phaser may be able to do that..

It's not possible. To be honest I don't really see a reason why you would want to do that , when you have all the easing functions available. In my mind, it makes perfect sense to only have those for paths.

  1. Is it possible to use getValue rather than getValues for saving memory when implement TweenAccessor?

Hmm, I have thought about this, but I think it would make the engine a bit confusing. Regardless, all "values" lists are fixed-size'd to whatever you set on Tween.combinedAttributesLimit, so memory should not really be an issue.

  1. I'll use only single value each time, and use timeline to implement field set combination.

Any reason why you don't want to set multiple fields at once? personally, I love being able to just use Tween.to........targetValues = [1, 2, 3]

  1. Why don't you just use CallbackHandler as the parameter of Tween.callBack?

Well, this was a straight port from the java original source, guess I messed up on a lot of things :smiley:

playif commented 9 years ago

Thanks for your reply.

Any reason why you don't want to set multiple fields at once? personally, I love being able to just use Tween.to........targetValues = [1, 2, 3]

I need to decouple each of fields, so that users can combine fields by them-self. For example, two fields, x and alpha, I will never build the combination in advance.

var tween = game.add.tween(sprite).to({
        X: 300,
        ALPHA: 0.1,
    }, 2000)

In the function "to", I used a parallel timeline object that contains multiple tweens (one for x, and one for alpha).

To be honest I don't really see a reason why you would want to do that , when you have all the easing functions available. In my mind, it makes perfect sense to only have those for paths.

You may be right, but I want to provide a consistent API for Phaser users. Is any possible way to determine when to use wayPoints (according to the above code sample)?

Tween.combinedAttributesLimit

Got it, I set the value to 1.

straight port from the java original source, guess I messed up on a lot of things

Will you fix it? If you do, let me know.

xaguzman commented 9 years ago

You may be right, but I want to provide a consistent API for Phaser users. Is any possible way to determine when to use wayPoints (according to the above code sample)?

I suppose that would be totally dependant on your wrapper. You could get an extra parameter from the user saying wether they want to use catrom spline or not. If they do, you could simply construct a path with 2 nodes, start value and end value (maybe even adding a a middle point?). Or even, allow them to specify how many "hotspots" are there in their tweens

Will you fix it? If you do, let me know.

Already fixed. this will be up on next version (0.10.1). the handler changed name, previously it was CallbackHandler. now it is TweenCallbackHandler

playif commented 9 years ago

Upgraded to 0.10.1 thanks.