I have made bird to change its rotation while mouseleft button is clicked .But I want that to be happen using tween.I used following code but it didnt work.Can you guys tell me the changes…
var Bird = pc.createScript('Bird');
Bird.prototype.initialize = function () {
this.isHit = 0;
this.jumpVelocity = 7;
this.maxJumpHeight = 4;
this.velocity = 0;
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onmousedown, this);
this.app.mouse.on(pc.EVENT_MOUSEUP, this.onmouseup, this);
};
Bird.prototype.onmousedown = function (event) {
if (event instanceof MouseEvent) {
event.stopPropagation();
}
if (event.button == pc.MOUSEBUTTON_LEFT) {
this.velocity = this.jumpVelocity + this.velocity;
//this.entity.setLocalEulerAngles(0, 0, 15);
this.entity.tween(this.entity.getEulerAngles()).to({ x: 0, y: 0, z: 15 }, 1, pc.SineOut).start();
}
};
Bird.prototype.onmouseup = function (event) {
if (event.button == pc.MOUSEBUTTON_LEFT) {
this.entity.setLocalEulerAngles(0, 0, -15);
}
};
Bird.prototype.update = function (dt) {
this.entity.translate(0, this.velocity * dt, 0);
this.velocity -= 9.8 * dt;
if (this.velocity > this.maxJumpHeight) {
this.velocity = this.maxJumpHeight;
}
var pos = this.entity.getLocalPosition().y;
if (pos <= -2.0) {
this.entity.sound.play("Die");
var GAME = this.app.root.findByTag("game");
var GAMEOVER = this.app.root.findByTag("go");
GAME[0].enabled = false;
//setTimeout(function () {
GAMEOVER[0].enabled = true;
//}, 350);
}
};