I made a sprite sheet with menu buttons in it and I load it through resource.js. I have 6 images for 3 buttons (normal/clicked state). I am having trouble getting any of the buttons to display. Here is my code to load the play button:
// Load menu buttons from menuButton Spritesheet
cc.spriteFrameCache.addSpriteFrames(res.menuButtons_plist);
var menuButtonsSpriteSheet = new cc.SpriteBatchNode(res.menuButtons_png);
this.addChild(menuButtonsSpriteSheet);
// Play Button
var playButton = new ccui.Button();
var playButton_n = cc.spriteFrameCache.getSpriteFrame("play_n.png");
var playButton_s = cc.spriteFrameCache.getSpriteFrame("play_s.png");
playButton.loadTextures(playButton_n, playButton_s);
playButton.addTouchEventListener(this.onPlay, this);
playButton.setAnchorPoint(cc.p(0.5, 0.5)); //Anchor centered
playButton.setPosition(centerPos);
this.addChild(playButton);
What am I doing wrong? Do spritesheets work with UI Buttons?
Debug is telling me Object not found, load image failed.
I tried looking at the Sprite Documentation but no luck in finding the right syntax to use for UI button. Is it the textures part?
I don’t know how to set the playButton.loadTextures(playButton_n, playButton_s) properly.
OMG thank you!!! I got it working after putting ,"", for the disabled parameter. I thought that was optional.
Both of these methods work: var playButton = new ccui.Button(“normal.png”, “selected.png”, “”, ccui.Widget.PLIST_TEXTURE);
And var playButton = new ccui.Button(); playButton.loadTextures(“normal.png”, “selected.png”, “”, ccui.Widget.PLIST_TEXTURE);
Do you know if playButton.setTouchEnabled(true); is needed?