Hello
I’m sorry the question, and my English XD, but I’m two days with an error and I am unable to solve it.
As I have not run the animation, I used the example of the url (http://www.gamefromscratch.com/post/2012/07/11/Cocos2D-HTML-Tutorial-5-Menus-and-sounds-and-music.aspx), and added your code, but I always get this error:
**TypeError: ani.addSpriteFrameWithFileName is not a function @ http://localhost/MyFourthApp/MyFourthApp.js:33
**
I am using Cocos2d-html5-v0.5.0-alpha2
This is the code I put (the rest of the files can be found here: http://www.gamefromscratch.com/post/2012/07/11/Cocos2D-HTML-Tutorial-5-Menus-and-sounds-and-music.aspx
@cc.LayerColor.extend MyFourthApp var = ({
init: function ()
{
this.initWithColor (cc.ccc4 (0,0,0,255));
var size = cc.Director.sharedDirector (). getWinSize ();
cc.AudioManager.sharedEngine (). setEffectsVolume (0.5);
cc.AudioManager.sharedEngine (). setBackgroundMusicVolume (0.5);
menuItem1 var = new cc.MenuItemFont.create (“Play Sound”, this, this.playSound);
MenuItem2 var = new cc.MenuItemFont.create (“Play Song”, this, this.playSong);
MenuItem3 var = new cc.MenuItemFont.create (“Stop Playing Song”, this, this.stopPlayingSound);
menuItem4 var = new cc.MenuItemFont.create (“Exit”, this, this.exit);
menuItem1.setPosition (cc.ccp (size.width / 2, size.height / 2 +50));
menuItem2.setPosition (cc.ccp (size.width / 2, size.height / 2));
menuItem3.setPosition (cc.ccp (size.width / 2, size.height/2-50));
menuItem4.setPosition (cc.ccp (size.width / 2, size.height/2-100));
var menu = cc.Menu.create (menuItem1, MenuItem2, MenuItem3, menuItem4);
menu.setPosition (cc.ccp (0,0));
this.addChild (menu);
cc.Animation.create var ani = new (); / / create the animation
var sprite = cc.Sprite.create (“images/mario1.png”) / / create the object
sprite.setPosition (cc.ccp (100, 100)); / / set position
this.addChild (sprite) / / add it to the layer or scene
ani.addSpriteFrameWithFileName (“images/mario2.png”) / / add frame 0
ani.addSpriteFrameWithFileName (“images/mario3.png”) / / add frame 1
ani.setDelayPerUnit (1), / / set the delay time, in seconds
ani.setLoops (5) / / repeat the animation 5 times,
var action = cc.Animate.create (ani);
sprite.runAction (action);
return this;
}
PlaySound: function () {
cc.Log (“Playing sound”);
cc.AudioManager.sharedEngine (). playEffect (“Resources/effect2”);
}
playSong: function () {
cc.Log (“Playing song”);
cc.AudioManager.sharedEngine (). playBackgroundMusic (“Resources / background”, false);
}
stopPlayingSound: function () {
cc.Log (“Done playing song”);
if (cc.AudioManager.sharedEngine (). isBackgroundMusicPlaying ())
{
cc.AudioManager.sharedEngine (). stopBackgroundMusic ();
}
}
exit: function () {
document.location.href = “http://www.gamefromscratch.com”;
}
});
MyFourthApp.scene = function () {
var scene = cc.Scene.create ();
var layer = MyFourthApp.layer ();
scene.addChild (layer);
return scene;
}
MyFourthApp.layer = function () {
pret MyFourthApp var = new ();
if (ready && pRet.init ()) {
pret return;
}
return null;
}
Can you help?
Thank you!
Edu