cykod / Quintus

HTML5 Game Engine
http://html5quintus.com
GNU General Public License v2.0
1.41k stars 401 forks source link

Setting sprite and sheet for animation problem. #127

Open Xlander11 opened 10 years ago

Xlander11 commented 10 years ago

Hi,

I have one sprite sheet and for only one row the width and height of the tiles are smaller, so I've tried to compile the same sheet 2 times with different data.

But when I tried to set them in a function, I get an error TypeError: anim is undefined -> rate = anim.rate || p.rate,

Here is the code:

    hadouken: function(){
        console.log(this.p.sheet + ', ' +  this.p.sprite);
        this.set({sheet: 'attack', sprite : 'ken_attack'}); // setting the second compiled sheet and animations
        console.log(this.p.sheet + ', ' +  this.p.sprite);

        if(this.p.direction == "right")
            this.play('hadouken_pose_right', 1);
        else if(this.p.direction == "left")
            this.play('hadouken_pose_left', 1);

        this.set({sheet: 'ken', sprite : 'ken_movement'}); // setting the first compiled sheet and animations
        console.log(this.p.sheet + ', ' +  this.p.sprite);
    },

Here is the load function:

    Q.compileSheets( "ken.png", 'ken_movement.json');

    Q.animations('ken_movement', {
        run_right: {frames: [ 21, 22, 23, 24, 25], rate: 1/3, flip: false},
        run_left: {frames: [ 21, 22, 23, 24, 25], rate: 1/3, flip: "x"},
        idle_right: {frames: [7, 8, 9, 10], rate: 1/3, flip: false},
        idle_left: {frames: [7, 8, 9, 10], rate: 1/3, flip: "x"},
        jump_right: {frames: [57, 58, 59], rate: 1/2, flip: false, loop: false},
        midjump_right: {frames: [ 59, 60], rate: 1/2, flip: false, loop: false},
        jump_left: {frames: [57, 58, 59], rate: 1/2, flip: "x", loop: false},
        midjump_left: {frames: [ 59, 60], rate: 1/2, flip: "x", loop: false},
        /*hadouken_pose_right: {frames: [ 0, 1, 2, 3], rate: 1/3, flip: false, loop: false, trigger: 'fired_right'},
        hadouken_pose_left: {frames: [ 0, 1, 2, 3], rate: 1/3, flip: "x", loop: false, trigger: 'fired_left'},*/
        // both moved in the ken attack animations
        bullet_right: {frames: [28, 29], rate: 1/2, flip: false, loop: false},
        bullet_left: {frames: [28, 29], rate: 1/2, flip: "x", loop: false}
    });

    Q.compileSheets('ken.png', {
        "attack": {
            "tilew": 35,
            "tileh": 35,
            "sy": 335,
            "w": 490,
            "h": 35,
            "cols": 7,
            "rows": 1,
            "frames": 7
        }
    });

    Q.animation('ken_attack', {
        hadouken_pose_right: {frames: [ 0, 1, 2, 3], rate: 1/3, flip: false, loop: false, trigger: 'fired_right'},
        hadouken_pose_left: {frames: [ 0, 1, 2, 3], rate: 1/3, flip: "x", loop: false, trigger: 'fired_left'}
    });

Creating another Sprite object and adding it to the player Sprite will work, or is there another way to do so?