Mojo2 object scope and clearing ILayer/ILight
Monkey Forums/Monkey Bug Reports/Mojo2 object scope and clearing ILayer/ILight
| ||
Hi, I am having a couple issues with mojo2. The first is that I can't seem to create a mojo2 class object outside the scope on 'OnCreate' In the modified 'Renderer' demo (below) if you try to create a mojo2 object within a 'Field' it will fail with a 'Null' object. I have also tried creating a mojo2 class instances (object) outside of 'OnCreate' and also get a 'Null' object. So in the code below you can try to initialize an object within a 'Field' in the MyApp class and it will return a 'Null' Object. The second issue is in clearing a mojo2 render image layer (ILayer) and lights (ILight). I have added a class called 'Test' to this modified "Renderer' demo in which I clear the lights and layer. Within 'Test' (class) the ClearLight() method clears the ILayer and ILight lists. I think this is the right method to clear the layers and lights. The demo below continually adds to a layer then clears it. This slows the application to a crawl and I am either doing it wrong or it's a bug. ;) The best way to get a sense of what I mean is to put this demo (below) in the same directory as the 'Renderer' demo and run it. Then comment out the first two lines (commands) in 'OnRender' and run it again. You will see the difference in speed. Being able to add to a layer and clearing it each frame is what is needed to support scrolling tile maps. So I hope it's me thats wrong here. |
| ||
> The first is that I can't seem to create a mojo2 class object outside the scope on 'OnCreate' In the modified 'Renderer' demo (below) if you try to create a mojo2 object within a 'Field' it will fail with a 'Null' object Yes, this is a similar limitation to that with images - you can't create any graphics objects until the graphics system is initialized (eg: window+GL context is created) which doesn't happen until just before OnCreate. Your rendering code is slowing down because you are continually adding new tiles to the layer via the 'DrawImage' in AddLight. You only need to draw these tiles once, or you can use DrawList.Reset() to 'clear' a drawlist (although this will also clear shadowcasters). Thanks for the nice code sample too! |
| ||
Thanks for the nice code sample too! Way better then two lines of code. :D Once you made the above comments I started to see what mojo2 is doing with 'Renderer'. Here is my little demo using SetCameraMatrix() for screen scrolling. http://www.monkey-x.com/Community/posts.php?topic=10187 Neat stuff now that I grasp whats up :) Thanks! |