Practical development of WeChat js sdk: card production and playback (2), sdk card production

Source: Internet
Author: User

Practical js sdk development: card production and playback (2), sdk card production

Recently, my colleague developed a greeting card production APP Based on CanTK. Although I was not involved in the development, I provided technical support for CanTK and GameBuilder. I think some things are interesting, write a few blogs to share with you. This greeting card APP is completely open-source and can be modified and released as needed.

CanTK (Canvas ToolKit) is an open-source game engine and APP framework. It is a powerful tool for developing HTML5 games and apps. If you like it, add stars to it on github, your support is our motivation: https://github.com/drawapp8/cantk
0. First Show the final result:

Online run: http://gamebuilder.duapp.com/apprun.php? Appid = osgames1-821423377846894

Online Editing: http://gamebuilder.duapp.com/gamebuilder.php? Appid = osgames1-821423377846894

Scan the Code:

Today we will introduce the skeleton Animation:

To support skeleton animation, CanTK integrates DragonBones. It is very easy to add a skeleton animation through Gamebuilder, which can be implemented in two steps:

Step 1: drag a skeleton animation from the toolbar on the left to the scene.


Step 2: set the bone Animation Parameters, that is, the three files exported from the dragonebones tool.


The greeting card production APP is a bit special: Several cartoon characters in the New Year's greetings are skeleton animations, And we allow users to replace their portraits with their own portraits. Therefore, two functions are added to UISkeletonAnimation (the following code can be found in the github repository of CanTK ):

UISkeletonAnimation.prototype.getSlotRect = function(name) {    if(!this.armature) {        return null;    }    var slotList = this.armature._slotList;    for(var i = 0; i < slotList.length; i++) {        var iter = slotList[i];        if(iter.name === name) {            var display = iter.getDisplay();            return display.textureAtlasRect;        }    }    return null;}UISkeletonAnimation.prototype.replaceSlotImage = function(name, image, imageRect) {    if(!this.armature) {        return this;    }    var slotList = this.armature._slotList;    for(var i = 0; i < slotList.length; i++) {        var iter = slotList[i];        if(iter.name === name) {            iter.image = image;            iter.imageRect = imageRect;        }    }    return;}

We also need to Hack in the draw function of DragonBones:

<span style="color:#444444;">        function slotDraw(slot, ctx) {            var display = slot._displayBridge.getDisplay();            var texture = slot.getDisplay().textureAtlas;            if(!texture) {                var armatureDisplay = slot.getDisplay();                var armature = armatureDisplay.armature;                if(armature.draw) {                    armature.draw(ctx);                }                return;            }            var image = texture.image;            var r = display.textureAtlasRect;  </span><span style="color:#ff0000;">            if(slot.image && slot.imageRect) {                image = slot.image;                r = slot.imageRect;            }</span><span style="color:#444444;">            ctx.save();            m.identity();            m.appendTransform(display.x, display.y, display.scaleX, display.scaleY, 0,                display.skewX, display.skewY, display.anchorX, display.anchorY);            ctx.transform(m.a, m.b, m.c, m.d, m.tx, m.ty);            ctx.drawImage(image, r.x, r.y, r.width, r.height, 0, 0, r.width, r.height);            ctx.restore();        }</span>

All right, you can solve the bone animation problem.


Related Article

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.