私はこのMelonJSチュートリアルに従っています。OOP クラス、コンストラクターなどに慣れてきました。コンストラクターについていくつか質問があります。
次のコード スニペットでは...
1) init
melonJS の特別な関数 (私は API を読んで、http://melonjs.github.io/docs/me.ObjectEntity.html、メロンではないようです)、または JavaScript ですか? playerEntity が作成されると自動的に呼び出されるようです...何を呼び出しているのinit
ですか?
2) ( ) と呼ばれることもあればthis
( this.setVelocity
)とme
呼ばれることもあるようme.game.viewport.follow
です。それぞれいつ電話しますか?
3) 速度の場合、なぜ乗算する必要があるのaccel * timer tick
ですか? :this.vel.x -= this.accel.x * me.timer.tick;
/*-------------------
a player entity
-------------------------------- */
game.PlayerEntity = me.ObjectEntity.extend({
/* -----
constructor
------ */
init: function(x, y, settings) {
// call the constructor
this.parent(x, y, settings);
// set the default horizontal & vertical speed (accel vector)
this.setVelocity(3, 15);
// set the display to follow our position on both axis
me.game.viewport.follow(this.pos, me.game.viewport.AXIS.BOTH);
},
/* -----
update the player pos
------ */
update: function() {
if (me.input.isKeyPressed('left')) {
// flip the sprite on horizontal axis
this.flipX(true);
// update the entity velocity
this.vel.x -= this.accel.x * me.timer.tick;
} else if (me.input.isKeyPressed('right')) {