Quick start createjs example tutorial
Draw pictures Use (Bitmap)
to draw graphics, such as rectangles, circles, etc. Use (Shape) [Similar to changing coordinates x, y, increasing shadow, transparency alpha, reducing and enlarging scaleX/scaleY You can do it]
Draw text, use (Text)
There is also the concept of container Container, the container can contain multiple display objects
<script></script> //引入相关的js文件 <canvas></canvas> canvas = document.querySelector('#canvas' stage = rect = rect.graphics.beginFill("#f00").drawRect(0, 0, 100, 100stage.update();graphics can set some styles, Line width, color, etc., you can also call some methods to draw graphics, such as rectangle drawRect, circle drawCircle, etc. You can check the API yourself for details.
createjs.Ticker.setFPS(60);
stage.setChildIndex(red,1);
var contain = new createjs.Container(); contain.addChild(bgImg); contain.addChild(bitmap); stage.addChild(contain);嬹嬷嬬~The focus of this article is to draw images and process them
var bg = new createjs.Bitmap("./background.png"); stage.addChild(bg); stage.update();According to the normal drawing process of EaselJS above, the above The code snippet should display normally. However, it can only be displayed normally in some cases. This image resource needs to be loaded successfully before it can be new. Otherwise, there will be no image on the canvas. If there is resource preloading, you can use the above code directly. If not, then It needs to be drawn after the image is loaded onload
var img = new Image(); img.src = './img/linkgame_pass@2x.png'; img.onload = function () { var bg = new createjs.Bitmap("./background.png"); stage.addChild(bg); stage.update(); }Just drawing pictures is not enough. Createjs provides several methods for processing pictures:
stage = new createjs.Stage("gameView"); bg = new createjs.Bitmap("./img/linkgame_pass@2x.png"); bg.x = 10; bg.y = 10;//遮罩图形shape = new createjs.Shape(); shape.graphics.beginFill("#000").drawCircle(0, 0, 100); shape.x = 200; shape.y = 100; bg.mask = shape; //给图片bg添加遮罩stage.addChild(shape); stage.addChild(bg); stage.update();

6.2 Add filter effects to pictures
var blur = new createjs.BlurFilter(5,5,1); bg.filters = [blur];We found that the picture still did not become blurred. The reason is that the stage is refreshed immediately after adding a filter to the picture. The filter can only maintain the effect of one frame, and the second frame filter failed. After using the cache() method of the image, the filter effect can be maintained no matter how the stage is refreshed. Adding cache has many effects, such as improving FPS, caching, etc.
bg.cache(0,0,bg.image.width,bg.image.height);
stage = new createjs.Stage("gameView"); bg = new createjs.Bitmap("./img/linkgame_pass@2x.png"); bg.x = 10; bg.y = 10;var rect = new createjs.Rectangle(0, 0, 121, 171); bg.sourceRect = rect; stage.addChild(bg); stage.update();

easeljs事件默认是不支持touch设备的,需要以下代码才支持:
createjs.Touch.enable(stage);
对于Bitmap,Shape等对象,都可以直接使用addEventListener进行事件监听
bitmap = new createjs.Bitmap(''); bitmap.addEventListener(‘click’,handle);
<canvas></canvas>
注意,以上代码的width,height不同于css中的width,height。
比如,你在canvas内部绘制图片,用x,y轴进行定位,这里的x,y是相对于canvas这个整体。
我们再把canvas当成一整张图片使用css进行适配
canvas{ width: 100%; }
那么,就会有以下的效果,canvas会适配屏幕尺寸,里面的图片也会等比例变大变小。


The above is the detailed content of Quick start createjs example tutorial. For more information, please follow other related articles on the PHP Chinese website!

H5 provides a variety of new features and functions, greatly enhancing the capabilities of front-end development. 1. Multimedia support: embed media through and elements, no plug-ins are required. 2. Canvas: Use elements to dynamically render 2D graphics and animations. 3. Local storage: implement persistent data storage through localStorage and sessionStorage to improve user experience.

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.

Key elements of HTML5 include,,,,,, etc., which are used to build modern web pages. 1. Define the head content, 2. Used to navigate the link, 3. Represent the content of independent articles, 4. Organize the page content, 5. Display the sidebar content, 6. Define the footer, these elements enhance the structure and functionality of the web page.

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

HTML5 is the latest version of the Hypertext Markup Language, standardized by W3C. HTML5 introduces new semantic tags, multimedia support and form enhancements, improving web structure, user experience and SEO effects. HTML5 introduces new semantic tags, such as, ,, etc., to make the web page structure clearer and the SEO effect better. HTML5 supports multimedia elements and no third-party plug-ins are required, improving user experience and loading speed. HTML5 enhances form functions and introduces new input types such as, etc., which improves user experience and form verification efficiency.

How to write clean and efficient HTML5 code? The answer is to avoid common mistakes by semanticizing tags, structured code, performance optimization and avoiding common mistakes. 1. Use semantic tags such as, etc. to improve code readability and SEO effect. 2. Keep the code structured and readable, using appropriate indentation and comments. 3. Optimize performance by reducing unnecessary tags, using CDN and compressing code. 4. Avoid common mistakes, such as the tag not closed, and ensure the validity of the code.

H5 improves web user experience with multimedia support, offline storage and performance optimization. 1) Multimedia support: H5 and elements simplify development and improve user experience. 2) Offline storage: WebStorage and IndexedDB allow offline use to improve the experience. 3) Performance optimization: WebWorkers and elements optimize performance to reduce bandwidth consumption.

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor
