Createjs Series Tutorial easeljs_6_ drawing animated Catwalk (Spritesheet)

Source: Internet
Author: User
Tags addchild

Core JS Code:
var cjs = createjs,    canvas,    stage,     container,    w = window.innerwidth,    h =  window.innerheight;function init ()  {    //set canvas Properties      canvas = document.getelementbyid (' game ');    canvas.width = w;     canvas.height = h;    //Creating the Stage      Stage = new cjs. Stage (canvas);     container = new cjs. Container ();//Draw external container     stage.addchild (Container);     var data  = {        images: ["Imgs/dance.png"],         frames: {             width: 320,            height: 504,             count: 12         },        animations: {             dance: [0, 11]        }     };    var spritesheet = new cjs. Spritesheet (data),         animation = new cjs. Sprite (spritesheet,  "Dance");     animation.set ({x:0,y:0,scalex: w/320,scaley:h/ 504 });//Zoom to full screen     container.addchild (animation);     cjs. Ticker.setfps (15);//Set the game frame rate     cjs. Ticker.on ("tick",  stage);}

1:sprite Data Construction

var data = {images: ["imgs/dance.png"], frames: {width:320,//width of each frame height:504,// Height per frame count:12//Total number of frames}, animations: {dance: [0, 11]//Custom animation name}};

There are many forms of animation data construction, the size of each frame is the same and different, the same method is used here;

2: Full Frequency Show

var spritesheet = new CJs. Spritesheet (data), animation = new CJs. Sprite (Spritesheet, "Dance");//start execution of defined dance animation Animation.set ({x:0,y:0,scalex:w/320,scaley:h/504});//Zoom to full screen contain Er.addchild (animation);

Effect Demo:

Createjs Series Tutorial easeljs_6_ drawing animated Catwalk (Spritesheet)

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: 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.