COCOS2D-JS Engine Learning Notes

Source: Internet
Author: User

Scale9sprite

When using Scale9sprite.create uncaught typeerror:cannot call method ' create ' of undefined this error,

It was later found that by default, the modules in Project.json only comes with cocos2d modules, by checking frameworks/cocos2d-html5/ Moduleconfig.json, you can see that there is no ccscale9sprite.js this class in the Cocos2d module.

It's in the GUI, so you can add the "GUI" module to the modules, or it can be like me, In Moduleconfig.json write a myneedfulclass such module, inside add Ccscale9sprite.js this class, so long as the modules add "Myneedfulclass" on the line. One advantage is that you can not load other classes in the GUI. The test code is as follows

        var tmp = cc. Sprite.create (Res. BLOCK9);           var thesize = tmp.getcontentsize ();         var fullrect = Cc.rect (0,0, thesize.width,thesize.height);         var insetrect = Cc.rect (32,32,thesize.width-64,thesize.height-64);         var scale9sprite = cc. Scale9sprite.create (Res. Block9,fullrect,insetrect);        Scale9sprite.setcontentsize (thesize.width*3,thesize.height*2);        scale9sprite.x  = SIZE.WIDTH/2;        Scale9sprite.y = SIZE.HEIGHT/2;        this. AddChild (Scale9sprite);

Original Picture:

After the above code processing image:

The effect is a,b,c,d four angular size unchanged, top,bottom two sides of the horizontal stretching, left,right two sides of the longitudinal stretching, center of the Center both transverse and longitudinal stretching.

Used in a more suitable place, such as a button wizard.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.