Wahyu Hidayat Posted November 15, 2018 Share Posted November 15, 2018 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. Quote Link to comment Share on other sites More sharing options...
obiot Posted November 15, 2018 Share Posted November 15, 2018 Can u share your game.resource list to verify if background is the actual asset name ? (As opposed to the filename) Quote Link to comment Share on other sites More sharing options...
Wahyu Hidayat Posted November 16, 2018 Author Share Posted November 16, 2018 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' } ]; Quote Link to comment Share on other sites More sharing options...
obiot Posted November 17, 2018 Share Posted November 17, 2018 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. Wahyu Hidayat 1 Quote Link to comment Share on other sites More sharing options...
obiot Posted November 17, 2018 Share Posted November 17, 2018 also I'm on the 6.x master branch, which version of melonJS are u using ? (might be a bug in a previous version that was fixed since then) Quote Link to comment Share on other sites More sharing options...
Wahyu Hidayat Posted November 17, 2018 Author Share Posted November 17, 2018 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', 0, 0, { 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.