Home

Awesome

<p align="center"> <img src="./logo.png" style="width:150px"/> </p> <p align="center"> beta 0.5.1 </a> </p> <p align="center"> <a href='http://alloyteam.github.io/AlloyStick'> http://alloyteam.github.io/AlloyStick </a> </p>

本项目近期在进行重构,因此变动会比较大,如果您有什么好的想法,欢迎在这里提出 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:

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)

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

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

demoInstance.addRole(
        {
            roleName:'xiaoxiao',
            image:textureImg,
            data:AlloyData,
            fps:40
        },
        ['comeon',40,10,false],
        {
            x:250,
            y:300
        },
        {
            ifEase:true,
        }
    );

AlloyStick.roleNumbers()

AlloyStick.setVector(roleName)

AlloyStick.removeVector(roleName)

AlloyStick.showFPS(dom)

AlloyStick.hideFPS()

AlloyStick.pause(obj)

demoInstance.pause({
		value:false /*means restart*/
		roleName:"xiaoxiao"
	})

AlloyStick.clear()

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

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)

AlloyStick.removeRules(key,role)

AlloyStick.changeReplaceOrWait(replaceOrWait)

AlloyStick.rolePlayTo(roleName,actionConfig)

AlloyStick.start()

Licence

This content is released under the GPL License.