Hi, im working on a prototype to test cocos creator. I’have built a simple prefab with a sprite (square tile) and a cc.AudioClip.
Then I instantiate 10 tiles on screen and the tiles perform a jump action + play sound effect when touched.
It works great on laptop browser, OSX and iOS builds. However playing it on safari in my iphone4s and my ipad3, performance is not good.
The problem is: the first time I touch a tile, the sound does not work. When I touch another tile, then works great. I guess this is related on how the assets/components are loaded and the first time is not fast/good enough to play it.
This is a very simple prototype and sound does not work well. So I was wondering if Im doing something wrong, or this is a known issue.
here is my code:
greyTile prefab is a sprite with a script component called tileEvents.js
initGame.js
cc.Class({
extends: cc.Component,
properties: {
greyTile:{
default: null,
type:cc.Prefab,
}
},
initBoard: function(){
var mynode;
var myCanvas = cc.director.getScene();
for (var x = 0; x <13; x++)
{
mynode = cc.instantiate(this.greyTile);
mynode.setAnchorPoint(0,0);
myCanvas.addChild(mynode);
mynode.setPosition((mynode.width*x),300);
}
},
});
tileEvents.js
cc.Class({
extends: cc.Component,
properties: {
fxsound:{
url: cc.AudioClip,
default:null
}
},
onLoad: function () {
this.node.on(cc.Node.EventType.TOUCH_START, this.touchMe,this);
},
touchMe: function(touch)
{
cc.log ("event: ",event);
cc.log ("touch: ",touch);
var action = cc.jumpTo(0.55, 400, -200, 350, 1);
cc.audioEngine.playEffect(this.fxsound, false);
this.node.runAction(action);
},
});
And this is how it look likes in screen
Any help would be very much appreciated.
Thanks!