thomas-alrek / JSGame

JavaScript + Canvas 2D game engine
GNU General Public License v2.0
56 stars 6 forks source link

Change API #18

Open thomas-alrek opened 8 years ago

thomas-alrek commented 8 years ago

It would be better to have the transform and vector2 methods apply to the object itself, instead of returning a new instance.

Example:

//This is how it is today, it is way to verbose
var player1 = new Sprite({image: "player.png"});
var target = new Vector2({x: 100, y: 100});

player1.transform.position = player1.transform.position.add(player1.transform.position.lerp(player1.transform.position, target, Time.deltaTime));

Instead, we could rewrite the API to work like this:

var player1 = new Sprite({image: "player.png"});
var target = new Vector2({x: 100, y: 100});

player1.transform.position.lerp(target, Time.deltaTime);

This would seriously simplify things. So the functions, like add(), multiply(), lerp(), etc. would work directly on the object instance itself.