Setting UI Button width and height in cocos2d js android application

杀马特。学长 韩版系。学妹 提交于 2019-12-02 05:44:54

We can make a call to a function that can scale the size of the UIButton by performing an action. In this case, the following code might help:

 performScaleAction : function() 
 {
    var duration = 0;   // duration in seconds for performing this action
    var scaleX = 0.5;   // scale factor for X-axis
    var scaleY = 0.5;   // scale factor for Y-axis
    var scaleAction = new cc.ScaleTo(duration , scaleX , scaleY );
    this.runAction(scaleAction);
 }

Now, call the above function in the following way:

this.performScaleAction();
this.addChild(button);

So, if the actual height of the image used for creating the UIButton is h, in this case, the new size as displayed on the screen would be h times scaleX . Same for the width of the UIButton.
Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!