Home Web Front-end H5 Tutorial Skeleton animation implemented in canvas

Skeleton animation implemented in canvas

Jun 12, 2018 pm 04:58 PM
canvas

This article mainly introduces the relevant information about the sample code of canvas-based skeletal animation. The content is quite good. I will share it with you now and give it as a reference.

Recently I learned a kind of skeletal animation about canvas. Just by hearing this name, I know that it is different from the previous animation of canvas. I wonder if you are interested in learning about it?

I first saw the skeletal animation accidentally on the Tencent team, but since there are very few tutorials on its official website, there is only a small demo for reference, and the official downloaded case is also It's very strange that it can't run. Maybe my operation is wrong, but it doesn't matter. Let's learn about this very advanced skeleton animation through this small demo. I am also new to it and my understanding is not very comprehensive. Please forgive me

Before we begin, let’s first learn about AlloyStick

The official introduction says that AlloyStick is a skeletal animation engine developed using HTML5 technology and can be used for HTML5 animation development and HTML5 games. Developed; AlloyStick is mainly composed of two parts: a skeletal animation engine and a skeletal animation editor. The skeletal animation editor provides powerful skeletal animation editing functions. By setting animation keyframes and relying on powerful automatic tweening and bone relationships, you can create realistic , vivid Canvas skeleton animation, which can run smoothly on PC, mobile phones, tablets and other devices. Well, it’s easy to say and very attractive

The so-called skeletal animation literally means animation drawn through bones. So what do the bones here look like?

Yes, even if it looks like this, it is in line with expectations. After all, they have a very powerful automatic tweening function. You can think of how many parts are used. Connected in a smooth way, a bit like PS feathering

Since it is a very powerful function, there must be someone with its own unique advantages

  1. The animation is more realistic, This is for sure

  2. The picture takes up very little space, which can also be seen from the fact that this person only consists of three parts: head, hands and legs

  3. Transition animation is automatically tween, making the action more flexible

  4. Skeleton controllable

  5. Skeletal event frame, the animation goes straight and waits for a certain action Or a certain frame, triggering custom event behavior

  6. Action data inheritance, multiple characters can use a set of animation data

  7. Can be combined with the house engine

  8. Combine sprite animation to create hybrid animation

Let’s start with a small demo

A skeletal animation is mainly composed of 3 parts : Skeleton data, skinning data, and animation data. With these three parts of data, AlloyStick can render vivid skeletal animation. Of course, these three parts of data do not need to be generated manually. They only need to be operated in the editor to automatically generate them. After the data is generated, you can call and execute the skeletal animation as follows. The first step is to introduce alloysk.js, and then add the resource resource.js. It should be noted that the skinned png is introduced with the img tag, and of course it can also be loaded in js. resource.js includes skinning data, bone relationship data, and all action data including animation names and parameters. In the second step, the stage object Stage and the role object Armature are generated according to the new resource file, and the Stage object manages the Armature object. The playTo method is the core method, allowing the character to play different action animations. You can add events to switch between different actions. Finally start the stage stage.start().

// 第一步 还是要先搭建canvas
<canvas id="canvas" width="800px" height="600px">抱歉,你的浏览器不支持canvas,建议你使用Chrome浏览器</canvas>
Copy after login

// 第二步 以图片形式或者js方式引入蒙皮资源
<img src="img/texture.png" id="xiaoxiaoImg" style="display:none;">
Copy after login

// 第三步 引入alloysk.js和resource.js
// 第四步 准备工作
var canvas = document.getElementById(&#39;canvas&#39;)
var textureImg = document.getElementById(&#39;xiaoxiaoImg&#39;)
var scene = new alloyge.Scene(canvas.getContext(&#39;2d&#39;))
var player = new alloysk.Armature(&#39;xiaoxiao&#39;,textureImg)
// 第五步 制作动画
// 动作快慢 参数:动作状态,速度,初始速度,是否一直执行,这里还可以设置其他动作,比如翻滚 roll
// 更新了几个动作状态:run 奔跑  roll 翻滚  simpleHit 右手扔东西   secondHit  右手打拳
 //  jump_kick  侧踢 comeon 挑衅   relax 放松  soap 捡肥皂
player.playTo(&#39;run&#39;,50,15,true);
// 动画位置
player.setPos(300,300); 

player.setEaseType(true);		
scene.addObj(player);
 // 启动FPS监听器 (辅助功能 非必须)
alloyge.monitorFPS(scene);
// 开始场景里的动画,并且可以传入callback循环调用
// 最后一步 执行动画
scene.start(); 
// 效果就是下面这样奔跑的少年啦,原谅我还没开通做gif动画的大门……
Copy after login

Since I am new to this, I don’t understand many things very well. I will sort it out when I have time.

The above is the entire content of this article. I hope it will be helpful to everyone’s learning. Help, please pay attention to the PHP Chinese website for more related content!

Related recommendations:

Use html5 canvas encapsulates a pie chart that echarts cannot implement

How to use canvas to hold down the mouse and move to draw a trajectory

The above is the detailed content of Skeleton animation implemented in canvas. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Which schools use canvas? Which schools use canvas? Aug 18, 2023 pm 05:59 PM

Schools using canvas include Stanford University, MIT, Columbia University, University of California, Berkeley, etc. Detailed introduction: 1. Stanford University uses Canvas as its main online learning platform. Teachers and students at Stanford University use Canvas to manage and communicate course content, and learn through functions such as online discussions, assignment submissions, and exams; 2. Ma Provincial Polytechnic Institute and MIT also use Canvas as their online learning management system and conduct course management through the Canvas platform; 3. Columbia University, etc.

What are the canvas arrow plug-ins? What are the canvas arrow plug-ins? Aug 21, 2023 pm 02:14 PM

The canvas arrow plug-ins include: 1. Fabric.js, which has a simple and easy-to-use API and can create custom arrow effects; 2. Konva.js, which provides the function of drawing arrows and can create various arrow styles; 3. Pixi.js , which provides rich graphics processing functions and can achieve various arrow effects; 4. Two.js, which can easily create and control arrow styles and animations; 5. Arrow.js, which can create various arrow effects; 6. Rough .js, you can create hand-drawn arrows, etc.

Learn the canvas framework and explain the commonly used canvas framework in detail Learn the canvas framework and explain the commonly used canvas framework in detail Jan 17, 2024 am 11:03 AM

Explore the Canvas framework: To understand what are the commonly used Canvas frameworks, specific code examples are required. Introduction: Canvas is a drawing API provided in HTML5, through which we can achieve rich graphics and animation effects. In order to improve the efficiency and convenience of drawing, many developers have developed different Canvas frameworks. This article will introduce some commonly used Canvas frameworks and provide specific code examples to help readers gain a deeper understanding of how to use these frameworks. 1. EaselJS framework Ea

What are the details of the canvas clock? What are the details of the canvas clock? Aug 21, 2023 pm 05:07 PM

The details of the canvas clock include clock appearance, tick marks, digital clock, hour, minute and second hands, center point, animation effects, other styles, etc. Detailed introduction: 1. Clock appearance, you can use Canvas to draw a circular dial as the appearance of the clock, and you can set the size, color, border and other styles of the dial; 2. Scale lines, draw scale lines on the dial to represent hours or minutes. Position; 3. Digital clock, you can draw a digital clock on the dial to indicate the current hour and minute; 4. Hour hand, minute hand, second hand, etc.

What versions of html2canvas are there? What versions of html2canvas are there? Aug 22, 2023 pm 05:58 PM

The versions of html2canvas include html2canvas v0.x, html2canvas v1.x, etc. Detailed introduction: 1. html2canvas v0.x, which is an early version of html2canvas. The latest stable version is v0.5.0-alpha1. It is a mature version that has been widely used and verified in many projects; 2. html2canvas v1.x, this is a new version of html2canvas.

uniapp implements how to use canvas to draw charts and animation effects uniapp implements how to use canvas to draw charts and animation effects Oct 18, 2023 am 10:42 AM

How to use canvas to draw charts and animation effects in uniapp requires specific code examples 1. Introduction With the popularity of mobile devices, more and more applications need to display various charts and animation effects on the mobile terminal. As a cross-platform development framework based on Vue.js, uniapp provides the ability to use canvas to draw charts and animation effects. This article will introduce how uniapp uses canvas to achieve chart and animation effects, and give specific code examples. 2. canvas

What properties does tkinter canvas have? What properties does tkinter canvas have? Aug 21, 2023 pm 05:46 PM

The tkinter canvas attributes include bg, bd, relief, width, height, cursor, highlightbackground, highlightcolor, highlightthickness, insertbackground, insertwidth, selectbackground, selectforeground, xscrollcommand attributes, etc. Detailed introduction

Where are the canvas mouse coordinates? Where are the canvas mouse coordinates? Aug 22, 2023 pm 03:08 PM

How to get mouse coordinates for canvas: 1. Create a JavaScript sample file; 2. Get a reference to the Canvas element and add a listener for mouse movement events; 3. When the mouse moves on the Canvas, the getMousePos function will be triggered; 4. Use The "getBoundingClientRect()" method obtains the position and size information of the Canvas element, and obtains the mouse coordinates through event.clientX and event.clientY.

See all articles