How to create node in Cocos2d-x JS

Source: Internet
Author: User

1, the sprite sprite altogether 4 kinds of creation way

(1) Create according to the picture resource path

1234 //参数1:图片资源路径varsprite1 = cc.Sprite.create("res/zifeiyu.png");//参数1:图片资源路径,参数2:显示区域varsprite2 = cc.Sprite.create("res/zifeiyu.png",cc.rect(0,0,480,320));

(2) created according to the frame name in the plist file. Note: You must add a # symbol to the front to differentiate

12 //参数1:帧名字 frame namevarsprite = cc.Sprite.create(‘#zifeiyu.png‘);

(3) Create according to Sprite frame

123 varspriteFrame = cc.spriteFrameCache.getSpriteFrame("zifeiyu.png");//参数1:cc.SpriteFrame对象varsprite = cc.Sprite.create(spriteFrame);

(4) Create based on texture texture

12345 vartexture = cc.textureCache.addImage("zifeiyu.png");//参数1:纹理var sprite1 = cc.Sprite.create(texture);//参数1:纹理,参数2:显示区域varsprite2 = cc.Sprite.create(texture, cc.rect(0,0,480,320));

2, the text Labelttf altogether 2 kinds of creation way

(1) Create based on multiple parameters such as font, size, etc.

12 //参数1:显示字符串,参数2:字体,参数3:字号,参数4:宽高,参数5:定位varmyLabel = cc.LabelTTF.create(‘label text‘‘Times New Roman‘, 32, cc.size(320,32), cc.TEXT_ALIGNMENT_LEFT);

(2) According to the custom object cc. Fontdefinition Create

12345 varfontDef = new cc.FontDefinition();fontDef.fontName = "Arial";fontDef.fontSize = "32";//参数1:显示字符串,参数2:自定义对象cc.FontDefinitionvarmyLabel = cc.LabelTTF.create(‘label text‘, fontDef);

3, animation animation altogether 3 kinds of creation way

(1) Empty Create

12 //无参数varanimation1 = cc.Animation.create();

(2) created based on sprite frame (sprite frames)

123456789 var  spriteframearr = [] ; var  spriteframe = cache.getspriteframe ( "ipastimes.png" spriteframearr.push (spriteframe); //parameter 1: Sprite frame array var  animation1 = cc. Animation.create (Spriteframearr); //parameter 1: Sprite frame Array, parameter 2: Continuation time, in seconds var  animation2 = cc. Animation.create (spriteframearr, 0.2); //parameter 1: Sprite frame Array, parameter 2: Continuation time, in seconds, Parameter 3: number of cycles var  animation3 = cc. Animation.create (spriteframearr, 0.2,2);

(3) Create according to the action frame (animation frames)

12345678910 varanimationFrameArr = [];varanimationFrame = newcc.AnimationFrame();aFrame1.initWithSpriteFrame(spriteFrame1,0.5);animationFrameArr.push(animationFrame);//参数1:动画帧数组varanimation1 = cc.Animation.create(animationFrameArr);//参数1:动画帧数组,参数2:延续时间,单位为秒varanimation2 = cc.Animation.create(animationFrameArr, 0.2);//参数1:动画帧数组,参数2:延续时间,单位为秒,参数3:循环次数varanimation3 = cc.Animation.create(animationFrameArr, 0.2,2);

4, batch Spritebatchnode altogether 2 kinds of creation way

(1) According to the picture resource path

12 //参数1:图片路径,参数2:容量varspriteBatchNode = cc.SpriteBatchNode.create("res/animations/ipastimes.png", 50);

(2) According to the texture

123 vartexture = cc.textureCache.addImage("res/animations/ipastimes.png");//参数1:纹理,参数2:容量varspriteBatchNode = cc.SpriteBatchNode.create(texture,50);

5, Wizard Spriteframe altogether 2 kinds of creation way

(1) According to the picture resource path

1234 //参数1:图片路径,参数2:区域varframe1 = cc.SpriteFrame.create("res/ipastimes.png",cc.rect(0,0,90,128));//参数1:图片路径,参数2:区域,参数3:是否旋转,参数4:偏移量,参数5:原区域varframe2 = cc.SpriteFrame.create("res/ipastimes.png",cc.rect(0,0,90,128),false,0,cc.size(90,128));

(2) According to the texture

12345 vartexture = cc.textureCache.addImage("res/ipastimes.png");//参数1:图片路径,参数2:区域var frame1 = cc.SpriteFrame.create(texture, cc.rect(0,0,90,128));//参数1:图片路径,参数2:区域,参数3:是否旋转,参数4:偏移量,参数5:原区域varframe2 = cc.SpriteFrame.create(texture, cc.rect(0,0,90,128),false,0,cc.size(90,128));

6, particle effect particlesystem altogether 2 kinds of creation way

(1) According to the picture resource path

12 //参数1:粒子数量varparticle = cc.ParticleSystem.create(50);

(2) According to the texture

12 //参数1:粒子工具particleDesigner导出的文件varparticle = cc.ParticleSystem.create("res/particle.plist");

7, physical physicssprite altogether 4 kinds of creation way

(1) Create according to the picture resource path

1234 //参数1:图片资源路径varphysicsSprite1 = cc.PhysicsSprite.create("res/ipastimes.png");//参数1:图片资源路径,参数2:显示区域varphysicsSprite2 = cc.PhysicsSprite.create("res/ipastimes.png",cc.rect(0,0,480,320));

(2) created according to the frame name in the plist file. Note: You must add a # symbol to the front to differentiate

12 //参数1:帧名字 frame namevarphysicsSprite = cc.PhysicsSprite.create(‘#ipastimes.png‘);

(3) Create according to Sprite frame

123 varspriteFrame = cc.spriteFrameCache.getSpriteFrame("ipastimes.png");//参数1:cc.SpriteFrame对象varphysicsSprite = cc.PhysicsSprite.create(spriteFrame);

(4) Create based on texture texture

12345 vartexture = cc.textureCache.addImage("ipastimes.png");//参数1:纹理var physicsSprite1 = cc.PhysicsSprite.create(texture);//参数1:纹理,参数2:显示区域varphysicsSprite2 = cc.PhysicsSprite.create(texture, cc.rect(0,0,480,320));

8, big texture textureatlas altogether 2 kinds of creation way

(1) According to the picture resource path

12 //参数1:图片路径,参数2:容量vartextureAtlas = cc.TextureAtlas.create("res/animations/ipastimes.png", 50);

(2) According to the texture

123 vartexture = cc.textureCache.addImage("res/animations/ipastimes.png");//参数1:纹理,参数2:容量vartextureAtlas = cc.TextureAtlas.create(texture,50);

 

How to create node in Cocos2d-x JS

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.