Createjs Series Tutorial easeljs_4_ drawing pictures (Bitmap)

Source: Internet
Author: User

Core JS Code:
var cjs = createjs,    canvas,    stage,     container,    w = window.innerwidth,    h =  window.innerheight,    image;function init ()  {    // Set the Canvas property     canvas = document.getelementbyid (' Game ');     canvas.width = w;    canvas.height = h;    //Creating a stage     stage = new cjs. Stage (canvas);     container = new cjs. Container ();//Draw external container     stage.addchild (Container);     //load Image      image = new image ();    image.src =  "Imgs/1.png ";     image.onload = handleimageload;} Function handleimageload (Event)  {&NBsp;   var bitmap = new cjs. Bitmap (event.target);//cjs. Bitmap ("Imgs/1.png")  PS:  must be finished after the picture is loaded  img.onload execute     bitmap.x =  W - bitmap.getbounds (). width >>1;    bitmap.y = h -  bitmap.getbounds (). Height >>1;    bitmap.on (' click ', function  ( )  {        alert ();     });     //Join Scene     container.addchild (bitmap);     stage.update ();}

Explanation:

1: Create load Picture

Load image image = new image ();    IMAGE.SRC = "Imgs/1.png"; Image.onload = Handleimageload;

2: Instantiate a diagram

var bitmap = new CJs. Bitmap (event.target);//cjs. Bitmap ("Imgs/1.png") PS: Must be finished after the picture is loaded Img.onload execute

Ps:bitmap (Imgobj|imgurl) when it is imgurl, it must be executed after img.onload;

Demo Effect:

Createjs Series Tutorial easeljs_4_ drawing pictures (Bitmap)

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.