Crafty icon indicating copy to clipboard operation
Crafty copied to clipboard

[Enhancement] Crafty.attr({}) function?

Open ExperiBass opened this issue 6 years ago • 3 comments

To be honest, using the .attr property(?) is sorta annoying to use. Why not have it a function? It only takes up to 4 integers, so I think using it as .attr(x, y, w, h) would be much easier to use. Example:

var player = Crafty.e('2D, Canvas, Color, Fourway, Collision')
    .attr(200, 200, 10, 10)
// Other properties...

And then calling any additional properties as:

.props({
currHealth: 100
maxHealth: 100
// Other custom properties...
})

Would this work, or no?

ExperiBass avatar Dec 22 '18 01:12 ExperiBass

Having a separate method for setting x/y/w/h in one swoop would be reasonable, but I think attr should remain the general purpose setter.

(There's already an internal method called _setPosition that sets the x/y properties; something similar could be done for all four.)

starwed avatar Dec 24 '18 15:12 starwed

Huh, i did not know that. I see your point as the general setter, is it possible to "compact" it?

ExperiBass avatar Dec 25 '18 01:12 ExperiBass

Also, quick question. Where are the docs for the .clone() method? I cant find them anywhere. Crafty.e refers to Crafty.c, which refers back to .e.

ExperiBass avatar Dec 25 '18 02:12 ExperiBass