i have a button script on a button
var Button = pc.createScript('button');
Button.attributes.add('shift', {type: 'number'});
var self;
var jumpBy;
// initialize code called once per entity
Button.prototype.initialize = function() {
self = this;
jumpBy = self.shift;
};
// update code called every frame
Button.prototype.update = function(dt) {
self.entity.button.on('click', this.onRelease, this);
};
Button.prototype.onRelease = function () {
self.app.fire('game:Next', jumpBy);
};
When I click on it. the game:Next
triggers every frame continuously rather than just once.
what have I done wrong?
if needed, you can give a look on the responder script
var ChangeMaterial2 = pc.createScript('changeMaterial2');
var _app;
var _myID;
var _Material;
var URL_prefix ='https://s3-us-west-2.amazonaws.com/ticomsoft-image-repo/';
var URL_sufix = '.png';
// exposed fields
ChangeMaterial2.attributes.add("targetMaterial", {type: 'number'}); //targetMaterial
ChangeMaterial2.attributes.add("ID", {type: 'number'}); //ID
var imageUrl;
var material;
ChangeMaterial2.prototype.initialize = function() {
var self = this;
_Material = self.targetMaterial;
_myID = self.ID;
_app=self.app;
material = self.entity.model.meshInstances[_Material].material;
// listen for the player:move event
// self.app.on('game:Next', self.UpdateID(shift));
var ImgFromURLwithCORS = function()
{
// allow cross origin texture requests
_app.loader.getHandler("texture").crossOrigin = "anonymous";
var asset = new pc.Asset("myTexture", "texture", {
url: imageUrl
});
_app.assets.add(asset);
asset.on("load", function (asset) {
material.diffuseMap = asset.resource;
material.update();
});
_app.assets.load(asset);
};
var UpdateID = function()
{
imageUrl = URL_prefix+_myID+URL_sufix;
ImgFromURLwithCORS();
};
var NextImage = function (jump)
{
_myID+=jump;
UpdateID();
console.log(jump);
return;
};
_app.on('game:Next',NextImage, this);
};