Wahyu Hidayat

Can't Add Image Layer from PNG

Recommended Posts

I can't instantiate an image layer from .png file. Is it right?

me.game.world.addChild (new me.ImageLayer (0, 0, { image: 'background' }), 1);

I can't get the documentation clearly from http://melonjs.github.io/melonJS/docs/me.ImageLayer.html, I want to create a scrollable background, i looked at tutorial from http://melonjs.github.io/tutorial-platformer/ but i just get the load process from TMX, i just want from normal png, can anyone help me, thank you.

I've add the resource image 'background' to game.resources and load it successfully, because other image file there can be displayed by entity/sprite in my game.


Share this post

Link to post
Share on other sites

My concern is about my implementation. Is it the right implementation? or i did some mistake on parameter there. Because the error is:

Uncaught o {name: "me.Vector2d.Error", message: "invalid x,y parameters (not a number)"}


Anyway, my game resource is below and i can display my player sprite in the game:

game.resources = [
{ name: 'player', type: 'image', src: 'data/img/player.png' },
{ name: 'background', type: 'image', src: 'data/img/background.png' }

Share this post

Link to post
Share on other sites

there is must be something not right somewhere, because I just tried on my side and the following is perfectly working :

me.game.world.addChild(new me.ImageLayer(0,0, {image:"cityscene"}), 1);

and cityscape is the name of an png image with the src set to "data/img/cityscene.png"

Are you sure, the path to the image is correct, and that the image is properly returned by your server ? Else, can you share your example, because just like this I have no clue why it's not working. 

Share this post

Link to post
Share on other sites

I'm using melonJS 6.1.0, sorry Mr. obiot for bothering your time, i've figured out my mistake, it was not about the imageLayer implementation, it's about my player update. When i use:

me.game.viewport.moveTo (0, this.pos.y);

I got an error like before, but when i change it to:

me.game.viewport.pos.y = this.pos.y;

the game was running perfectly. And I got that error only if i instantiate the background and player together. Like this:

me.game.world.addChild (new me.ImageLayer (0, 0, { image: 'background' }), -1);
me.game.world.addChild (me.pool.pull ('player'00, { image: 'player', width: 10, height: 10, framewidth: 10, frameheight: 10 }), 1);

If i just instantiate one of them, me.game.viewport.moveTo (0, this.pos.y); also works fine. I don't know why. But thank you for helping me, my problem has been solved :D

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.