Jump to content

Can't Add Image Layer from PNG


Wahyu Hidayat
 Share

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.

 
Link to comment
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' }
];
Link to comment
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. 

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...