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

init (True) and TMX loadLevel issue #39

Closed
norb42 opened this issue Jan 25, 2012 · 8 comments
Closed

init (True) and TMX loadLevel issue #39

norb42 opened this issue Jan 25, 2012 · 8 comments
Labels

Comments

@norb42
Copy link

norb42 commented Jan 25, 2012

Hello,

I'm quite new with MelonJs but I show something that I didn't expect and didn't find any topic related to that point.

Inside an init function if you place this.parent(true) you should be able to use draw and update function (http://www.melonjs.org/docs/symbols/me.ScreenObject.html#init), but if you load a TMX level those function are still not activated.

Code to test :

var PlayScreen = me.ScreenObject.extend(
{
init: function()
{
//can't work with a loadlevel
this.parent(true);

},

onResetEvent: function() 
{
    me.levelDirector.loadLevel("area01");
},


update: function() 
{       
    //can't work since a loadlevel is in place
    alert("this never occur, if you comment the load level it will work without trouble");
}

});

I think this is a bug since if we want to place keyb action not on object of the TMX but inside the PlayScreen 'class' we can't do it properly.

Thanks for your feedback.

PS: MelonJS is quite interesting, thanks for your work !!

@melonjs
Copy link
Collaborator

melonjs commented Jan 26, 2012

wow, good catch, and I'll try to reproduce it later and will see what's wrong.
that's funny to see how major bugs can stay "unseen" for a long time anyway, I should have see that myself, but actually never did this this way :)

Thank you, and thank you for your feedback !

@melonjs
Copy link
Collaborator

melonjs commented Jan 26, 2012

Ok, so I found the issue, since it's not a 5mn correction and since you maybe not use the github 0.9.3 version, here is a workaround that will also work with version 0.9.2 :

onResetEvent: function()
{
me.levelDirector.loadLevel("area01");
me.game.add(this, zIndex) // just put 0 for zIndex if you want to draw stuff in the background, or 999 in the foreground
me.game.sort() // no necessary if you use a very high value (except if you have a tons of object!)
},

tell me it it does the trick for you.

@norb42
Copy link
Author

norb42 commented Jan 26, 2012

update event still not occur :(

When the next release will come ? I have find out some work arround to do what I want so I can perhaps just wait :)

@melonjs
Copy link
Collaborator

melonjs commented Jan 27, 2012

oh... then it might be a little bit harder to fix :)

just for me to know which kind of workaround are you using ?
on my side when I was saying that i never saw this bug before it's because I never basically mixed them (I don't actually recall I did). I use the update/draw function when I don't use the tile map loader (basically to draw a loading screen), and the "regular" way for all the rest. And If I need to add some overlay information, if not HUD stuff I just create a specific object (that itself by default use the update/draw stuff) and do/draw my stuff from it. And to be honest, the screen object stuff is more like hackish stuff to me, but i haven't yet decided myself what to do exactly with it :)

anyway, if you have a good workaround go ahead with it, the next release won't happen before I finished working on the Tiled map (to get isometric map working, JSON file loading) and add better mouse and touch event. That's more or less my plan for the next release, although I could split this depending if a new version if a major feature or bug correction is required.

i will anyway let this ticket opened until a proper solution is found :)

@norb42
Copy link
Author

norb42 commented Jan 27, 2012

it's actually what I did, I was first thinking of placing some code on the screen object to manage some action (opening of door) but finally I just place the code inside the object itself but I have shown another annoying thing doing that and will open another thread :)

So yes please let it open until it's corrected because I still think for clarity of the code some object must be place on the screen

@norb42
Copy link
Author

norb42 commented Jan 28, 2012

By the way if you can correct this bug and add the following features it can be interesting :)

  • Tiled layer access : we can't have access to the tiled layer from our code (all attribute are private ) I think that can be interesting to be able to change directly tile on the map layer instead of placing new sprite on top, that can also apply to colision layer :)
  • merge TMX map function :
    parameters : this function will take 4 parameters, X, Y, TMXmapName, Z : the Z can be optional
    Goal : place a TMX inside an other TMX
    how to use : something like that :
    me.levelDirector.loadLevel("area01");
    me.levelDirector.mergeWithLevel(10,10,30, "labyrinthechange");

What do you think ?

@melonjs
Copy link
Collaborator

melonjs commented Jan 29, 2012

For this first point, you can actually already access the layer information :

From your game you can call the following function to get a reference to the required layer :
me.game.currentLevel.getLayerByName(“layerName”);

And from that point you can call all the corresponding function, like getTile, setTile, etc... Where you are right, is that this is not yet documented, but with the code rewrite i've done in this version (on which I still need to work I'll add this in the documentation). In the meantime, you can check the source code and the following objects :
me.TMXLayer (TMXTiledMap.js) that inherits from me.TiledLayer (level.js)
now if you wonder why I have this inheritance here, that's because I kind of made this having in mind the possibility (one day!) to support other format that the TMX one (although this will for sure require more work).

For the second point, I'm not sure I actually really understand the usage for it.
But for sure merging layer "on-the-fly" would need some work to be done, but I rather prefer to focus on other priorities on my side : finish the isometric support (now that isometric maps can be properly displayed in the current build, I need to also manage collision in an isometric way), rewrite the mouse support, and add touch event support.

Also, if you don't mind I'd prefer you to create a new ticket, if you really think this is a needed feature.

@melonjs
Copy link
Collaborator

melonjs commented Jul 25, 2012

ok this was automatically closed by github (just realized it's automatic when you put "Fixed" before the ticket number), please however come and discuss this on ticket #75, as they are both the same :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant