1
0
forked from sent/waves
waves/public/assets/g/flappybird/files/assets/64308082/1/sparkle.js
2025-04-09 17:11:14 -05:00

21 lines
794 B
JavaScript

var Sparkle = pc.createScript('sparkle');
Sparkle.attributes.add('radius', { type: 'number', default: 1 });
// initialize code called once per entity
Sparkle.prototype.initialize = function() {
this.initialPos = this.entity.getLocalPosition().clone();
// On every new loop of the sprite animation, restart it in a different, random
// position within the bounds of the medal
this.entity.sprite.on('loop', function () {
// Calculate a random point within a circle
var angle = Math.random() * Math.PI * 2;
var radius = Math.random() * this.radius;
var x = Math.cos(angle) * radius;
var y = Math.sin(angle) * radius;
this.entity.setLocalPosition(this.initialPos.x + x, this.initialPos.y + y, this.initialPos.z);
}, this);
};