hexonaut / haxe-phaser

Haxe externs for Phaser.
MIT License
51 stars 9 forks source link

phaser.animation.Class<Animation> has no field generateFrameNames #9

Closed plicatibu closed 10 years ago

plicatibu commented 10 years ago

I believe this error is being caused because the function generateFrameNames has returns Void in Haxe and in JavaScript it returns an array.

The generated Animation.hx class (full code):

package phaser.animation;

@:native("Phaser.Animation")
extern class Animation {

function generateFrameNames (prefix:String, start:Float, stop:Float, ?suffix:String = '', ?zeroPad:Float = 0):Void;
}

The Animation.js class (full source code):

Phaser.Animation.generateFrameNames = function (prefix, start, stop, suffix, zeroPad) {

    if (typeof suffix == 'undefined') { suffix = ''; }

    var output = [];
    var frame = '';

    if (start < stop)
    {
        for (var i = start; i <= stop; i++)
        {
            if (typeof zeroPad == 'number')
            {
                //  str, len, pad, dir
                frame = Phaser.Utils.pad(i.toString(), zeroPad, '0', 1);
            }
            else
            {
                frame = i.toString();
            }

            frame = prefix + frame + suffix;

            output.push(frame);
        }
    }
    else
    {
        for (var i = start; i >= stop; i--)
        {
            if (typeof zeroPad == 'number')
            {
                //  str, len, pad, dir
                frame = Phaser.Utils.pad(i.toString(), zeroPad, '0', 1);
            }
            else
            {
                frame = i.toString();
            }

            frame = prefix + frame + suffix;

            output.push(frame);
        }
    }
    return output;
}

Regards.

plicatibu commented 10 years ago

Hi. Sorry to tell you that the problem persists.

The official example example of Phaser named animation: group creation works perfectly and without any warning / error.

But it's version converted to Haxe generates the error message

phaser.animation.Class<Animation> has no field generateFrameNames

Official Phaser sample:

//  These are the frame names for the octopus animation. We use the generateFrames function to help create the array.
var frameNames = Phaser.Animation.generateFrameNames('octopus', 0, 24, '', 4);

Haxe code:

//  These are the frame names for the octopus animation. We use the generateFrames function to help create the array.
var frameNames = Animation.generateFrameNames('octopus', 0, 24, '', 4);

You can see the full haxe code here

hexonaut commented 10 years ago

Looks like the problem is the function should be static. I'll fix this shortly.