Is there a way use sprite sheets for button states in Cocos Studio?

Hi there

In Cocos Studio it’s easy to setup the button states by dragging the respective images onto the state boxes.

But is there a way to get the buttons to use images from a sprite sheet, so all UI can be in one image file?

Thanks in advance?

Technically it’s possible but I’m not sure if that’s gonna work in Cocos studio since you will need to write the codes by yourself. You just need to use the same create function from UIButton class and change the texture resource type from LOCAL to PLIST ( i.e. cocos2d::ui::Button::create("normalImg", "selectedImg", "disabledImg", TextureResType::PLIST); )

Thanks for the reply!

I ended up having to do just that.

I am using the Cocos Studio sprite sheet creator. When I publish the project it exports the sprite sheet but uses full paths for the images, which is quite annoying, as I have to manually convert them to just the filenames in the plist file, so I can map the images correctly based on the screen size. Perhaps in a future update Cocos Studio will allow exporting of just filenames.

You should be able to use them as the button state images. Just import the spritesheet into Coco Studio and drag and drop the image from the spritesheet onto the button.

Your sprite sheet should look something like this in Coco Studio and you should be able to drag those images onto your buttons

1 Like

Thanks for this TheCodez, it works!

Hi @TheCodez, @GarthWood,

How’d you guys get this to work?

I import the spritesheet and I get this:

Then I click and drag the frame from the spritesheet onto the button, but it only creates a new Sprite on the layer.

I also tried to click and drag it onto the squares here:

But this does nothing.

You guys know if it is possible to use a certain sprite as a button state. A sprite with child sprites for example?