Hello, I am a new coder and I have forked Flappy Bird from @Will and I have made it more like the original game. However I am stuck on how to stop a sine effect when you click to trigger another event
This is the sine code:
var Sine = pc.createScript('sine');
Sine.attributes.add('amplitudeScale', { type: 'number', default: 1 });
Sine.attributes.add('frequencyScale', { type: 'number', default: 1 });
Is there anyway to stop this when you click? Sorry if this is a stupid question. Any help is appreciated 
You could do it like this:
var Sine = pc.createScript('sine');
Sine.attributes.add('amplitudeScale', { type: 'number', default: 1 });
Sine.attributes.add('frequencyScale', { type: 'number', default: 1 });
// initialize code called once per entity
Sine.prototype.initialize = function() {
this.timer = 0;
this.sineActive = true;
this.app.on('EVENT', function() {
this.sineActive = false;
}, this);
};
// update code called every frame
Sine.prototype.update = function(dt) {
if(this.sineActive) {
dt *= this.frequencyScale;
this.timer += dt;
this.entity.setLocalPosition(0, Math.sin(this.timer) * this.amplitudeScale, 0);
}
};
You just need to replace “EVENT” with the actual event you want to listen to.
1 Like