• Stars
    star
    437
  • Rank 99,659 (Top 2 %)
  • Language
    JavaScript
  • Created almost 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AlloyStick 骨骼动画引擎 - 腾讯 AlloyTeam

beta 0.5.1

http://alloyteam.github.io/AlloyStick

本项目近期在进行重构,因此变动会比较大,如果您有什么好的想法,欢迎在这里提出 magic分支:正在开发的分支

CONTENT

Demo

We have a demo in this project, you can download the project and run example/stickman/index.html by yourself.

Usage

We only exposed two variables(classes) for the window. So all operations are based on these two classes:

window.AlloyStick
window.AlloyUtils 

attention: window.AlloyUtils may be removed soon

Here is a suggested workflow to start your animation:

1.create a scene

the only parameter is the context for the canvas.

let demoInstance = new window.AlloyStick({context:canvas.getContext('2d')});

2.add an role

A scene can has servel roles(objects), you can add roles one by one manually.

there are four parameters:

  • the config for the role
  • the initial action([{String}animationName,{Number}totalFrames,{Number}transitionFrames,{bool}isloop] and the order of this array can not be changed)
  • the position of the Object([{Number}x,{Number}y])
  • Whether to call the easing function(In fact the easing function can be redefined by yourself in futher)
demoInstance.addRole(
        {
            roleName:'xiaoxiao',
            image:textureImg,
            data:AlloyData,
            fps:40
        },
        ['comeon',40,10,false],
        {
            x:250,
            y:300
        },
        {
            ifEase:true,
        }
    );

3.bind events

You can call the actions by using function rolePlayTo, but the more convenient way is to bind a key to an event: when the user press down the certain key , an action should be called.

The second parameter means the action is called whether 'keydown' or 'keyup'.

The third parameter are some hook functions. There are four hooks totally:

beforeKeyDown
afterKeyDown
beforeKeyUp
afterKeyUp

The forth parameter is important : there are two modes for the animation: the wait mode and the replace mode. In the wait mode, all the triggerd animations will be in an array and acts one by one, pressing a keyboard button for many times quickly can cause the accumulation of animations. But in the replaced mode, the animation being executed can not be interrupted, but there is at most one animation waiting, and there is no accumulation of animations.

the two modes can be used in different scenes.

Finally the example:

demoInstance.mapKeyToAni(
        {
            'j':{rules:[{role:'xiaoxiao',action:['simpleHit',12,5,false]},{role:'dada',action:['simpleHit',12,5,false]}]},
            //others are omitted
        },
        'keydown',
        {
            beforeKeyDown:function(e){
                let doms = document.getElementsByClassName('key_'+e.key);
                for(let i = 0; i<doms.length; i++){
                    AlloyUtils.addClass(doms[i],'pressdown');
                }
            },
            afterKeyUp:function(e){
                let doms = document.getElementsByClassName('key_'+e.key);
                for(let i = 0; i<doms.length; i++){
                    AlloyUtils.removeClass(doms[i],'pressdown');
                }
            }
        },
        'replace',
    );

4.start

Just start the instance:

demoInstance.start();

This step is necessary, otherwise all actions can not be performed.

API

window.AlloyStick

new AlloyStick(config)

  • arguments:
    • {Object} config
  • return: the instance of AlloyStick
  • example:
let demoInstance = new window.AlloyStick({context:canvas.getContext('2d')});

AlloyStick.addRole(roleConfig,initialAction,initialPosition,easeConfig)

  • arguments:
    • {Object} roleConfig
    • {Object} initialAction
    • {Object} initialPosition
    • {Object} easeConfig
      • default:{ifEase:false}
      • Optional
  • return: no return
  • usage: add role to this instance's scene(an instance of AlloyStick has only one scene)
  • example:
demoInstance.addRole(
        {
            roleName:'xiaoxiao',
            image:textureImg,
            data:AlloyData,
            fps:40
        },
        ['comeon',40,10,false],
        {
            x:250,
            y:300
        },
        {
            ifEase:true,
        }
    );

AlloyStick.roleNumbers()

  • arguments: no arguments
  • return: {Number}
  • usage: return the number of roles of this AlloyStick instance

AlloyStick.setVector(roleName)

  • arguments:
    • {String} roleName
      • Optional
  • return: no return
  • usage: change all the roles(when the roleName is undefined) or certain roles to the vector mode

AlloyStick.removeVector(roleName)

  • arguments:
    • {String} roleName
      • Optional
  • return: no return
  • usage: change all the roles(when the roleName is undefined) or certain roles to the normal mode

AlloyStick.showFPS(dom)

  • arguments:
    • {String|dom} dom
      • Optional
  • returns: no return
  • usage: show the fps monitor

AlloyStick.hideFPS()

  • arguments: no argument
  • return: no return
  • usage: hide the fps monitor

AlloyStick.pause(obj)

  • arguments:
    • {Object} obj
      • Optional
  • return: no return
  • usage: pause or restart the whole scene(if obj is undefined or no roleName is defined in the obj) or the certain role
    • hint: when no 'value' property is specified in the obj, the pause means switch state, pause() twice means restart
  • example:
demoInstance.pause({
		value:false /*means restart*/
		roleName:"xiaoxiao"
	})

AlloyStick.clear()

  • arguments: no arguments
  • return: no return
  • usage: clear the whole scene of this instance

AlloyStick.mapKeyToAni(lists,keyDownOrUp,callBacks,replaceOrWait = 'wait')

  • arguments:
    • {Object} lists
    • {'keydown'|'keyup'} keyDownOrUp
    • {Object} callBacks
    • {'wait'|'replace'} replaceOrWait
      • default: 'wait'
      • Optional
  • return: no return
  • usage: map the keyboard buttons to actions
  • example:
demoInstance.mapKeyToAni(
        {
            'j':{rules:[{role:'xiaoxiao',action:['simpleHit',12,5,false]},{role:'dada',action:['simpleHit',12,5,false]}]},
            //others are omitted
        },
        'keydown',
        {
            beforeKeyDown:function(e){
                let doms = document.getElementsByClassName('key_'+e.key);
                for(let i = 0; i<doms.length; i++){
                    AlloyUtils.addClass(doms[i],'pressdown');
                }
            },
            afterKeyUp:function(e){
                let doms = document.getElementsByClassName('key_'+e.key);
                for(let i = 0; i<doms.length; i++){
                    AlloyUtils.removeClass(doms[i],'pressdown');
                }
            }
        },
        'replace',
    );

AlloyStick.addRules(lists)

  • arguments:
    • {Object} lists
  • return: no return
  • usage: add the rules for mapping the keyboard buttons to actions

AlloyStick.removeRules(key,role)

  • arguments:
    • {String} key
    • role
      • optional
  • return: no return
  • usage: add the rules for mapping the keyboard buttons to actions(if the parameter role is undefined, remove all the actions for the key, else remove the actions of the certain role for the key)

AlloyStick.changeReplaceOrWait(replaceOrWait)

  • arguments:
    • {'wait'|'replace'} replaceOrWait
  • return: no return
  • usage: change the mode to 'wait' mode or 'replace' mode.

AlloyStick.rolePlayTo(roleName,actionConfig)

  • arguments:
    • {String}roleName
    • {Array}actionConfig
      • hint: [{String}animationName,{Number}totalFrames,{Number}transitionFrames,{bool}isloop]
  • return: no return
  • usage: Use js to call the action

AlloyStick.start()

  • arguments: no argument
  • return: no return
  • usage: start this Instance

Licence

This content is released under the GPL License.

More Repositories

1

Mars

腾讯移动 Web 前端知识库
9,612
star
2

AlloyFinger

Super tiny size multi-touch gestures library for the web.    You can touch this →
JavaScript
3,418
star
3

AlloyImage

基于HTML5的专业级图像处理开源引擎。An image processing lib based on html5.
JavaScript
3,018
star
4

PhyTouch

Smooth scrolling, rotation, pull to refresh, page transition and any motion for the web - 丝般顺滑的触摸运动方案
JavaScript
2,968
star
5

eslint-config-alloy

Progressive ESLint config for your React/Vue/TypeScript projects
JavaScript
2,641
star
6

AlloyLever

1kb js library contains development debugging, error monitoring and reporting, user problem localization features - 1KB代码搞定开发调试发布,错误监控上报,用户问题定位
JavaScript
1,382
star
7

curvejs

Made curve a dancer in HTML5 canvas - 魔幻线条
JavaScript
1,303
star
8

CodeGuide

Alloyteam代码规范
HTML
1,279
star
9

JX

JX(Javascript eXtension tools) 是腾讯AlloyTeam推出的模块化、非侵入式Web前端框架,适合构建和组织工业级大规模、高效率的 Web App
JavaScript
1,153
star
10

AlloyCrop

The best and tiny size mobile cropping component - 做最好且最小的移动裁剪组件
JavaScript
941
star
11

Rythem

a fiddler-like project using Qt
C++
888
star
12

alloyteam.github.com

腾讯 AlloyTeam 开源项目官网 - 我们的愿景: 成为业界卓越的Web团队!
JavaScript
849
star
13

alloy-worker

面向事务的高可用 Web Worker 通信框架
TypeScript
644
star
14

Rosin

A tool for web developers debug mobile page with fiddler. http://alloyteam.github.io/Rosin/
C#
312
star
15

StreetFighter

街霸StreetFighter
JavaScript
305
star
16

webtop

HTML5 本地App开发引擎
C++
290
star
17

AlloyPhoto

JavaScript
277
star
18

gopng

GoPng - a HTML5 css sprite generator with cool feature.
273
star
19

sodajs

Light weight but powerful template engine for JavaScript
JavaScript
257
star
20

tslint-config-alloy

AlloyTeam TSLint 规则
JavaScript
205
star
21

JXAnimate

基于CSS3的并行动画、声音引擎 - JX.Animate
CSS
195
star
22

AlloyTimer

AlloyTimer定时器 - 番茄工作法的时间管理应用
JavaScript
195
star
23

JMUI

移动Web开发UI组件库
JavaScript
178
star
24

AlloyViewer

H5图片查看器—Imageview component built with react
JavaScript
176
star
25

JM

面向Mobile的极致JavaScript库
JavaScript
141
star
26

AlloyDesigner

AlloyDesigner是一款致力于提高前端生产效率的浏览器内运行工具,AlloyDesigner + Chrome F12(Especially with WorkSpace) 打造前端新的开发和测试模式
138
star
27

omi-cli

Create website with no build configuration - 创建网站无需任何配置
JavaScript
125
star
28

AlloyPullRefresh

JavaScript
119
star
29

Spirit

腾讯移动Web整体解决方案
CSS
117
star
30

CodeTank

CodeTank(代码坦克)是全世界首款 Javascript 程序员的游戏, 由腾讯 AlloyTeam 用 HTML5、Javascript 等 Web 新技术来构建一个基于互联网的智能坦克机器人战斗仿真引擎
114
star
31

AlloyClip

A PC & Mobile Image Clip Kit based on AlloyImage
JavaScript
108
star
32

MLogger

一个浮在页面上的日志查看工具
JavaScript
100
star
33

Abstract.js

Abstract.js is a web framework for fast development
JavaScript
46
star
34

AlloyLint

apply eslint autofix but keep last author info in git blame。运行 eslint 的自动修复,但是保留最后修改人的信息
TypeScript
41
star
35

AlloyFlow

made workflow simple
JavaScript
38
star
36

AlloyTicker

The Master of Time          DEMO
JavaScript
25
star
37

netural

JavaScript前向神经网络(推理)和反向传播(训练)的实现
JavaScript
22
star