Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating atlas through code #984

Closed
devnewton opened this issue Jan 3, 2020 · 1 comment
Closed

Creating atlas through code #984

devnewton opened this issue Jan 3, 2020 · 1 comment

Comments

@devnewton
Copy link

@devnewton devnewton commented Jan 3, 2020

I try to figure how to use some spritesheet ( like https://jb3.devnewton.fr/pasted/2da929eb-8783-4162-87a2-80ac4350ab81.jpg ).

Is it possible to define the atlas manually? Melonjs documentation only talk about Texture Packer or Shoebox.

I tried this:

        let atlas = {
            "meta": {
                "app": "melonJS",
                "size": {"w": 512, "h": 512},
                "repeat": "no-repeat",
                "image": "sara"
            },
            "frames": [{
                    "filename": "stand",
                    "frame": {"x": 1, "y": 1, "w": 32, "h": 48}
                }]
        };

       let texture = new me.video.renderer.Texture(
                atlas,
                me.loader.getImage("sara")
                );
        this.renderable = new me.Sprite(0, 0, {image: texture});
        this.renderable.addAnimation("stand", [{ name: "stand", delay: Infinity }]);
        this.setCurrentAnimation("stand");

But it is not detected as an atlas:

string parameters for addAnimation are not allowed for standard spritesheet based Texture

@obiot

This comment has been minimized.

Copy link
Member

@obiot obiot commented Jan 7, 2020

when creating sprite out of atlas, you should rather use the "createAnimationFromName" helper function :
http://melonjs.github.io/melonJS/docs/me.Renderer.Texture.html#.createAnimationFromName

so you should change the renderable definition to :

this.renderable = texture.createAnimationFromName(["stand"]);
this.renderable.addAnimation("stand", [{ name: "stand", delay: Infinity }]);
this.renderable.setCurrentAnimation("stand");

(also, be careful, you call setCurrentAnimation on this object instead of the renderable)

this should helpfully work now :P

@obiot obiot closed this Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.