Changing .render to allow for 10 z layers

I need more than the provided 3 z-layers!

In this example we have a background, on top of that some yellow tiles, and on top of that, a tree and two characters. The correct z order is

0 background
1 tiles
2 bottom half of tree
3 characters
4 top half of tree

The two halves of the tree are rendered separately to give a kind of faux 3D effect. It’s effective, isn’t it!!! sorry for the pixelisation.

Using the default render_script, you can still pick an arbitrary amount of z-levels, you just need to keep them between -1,1. E.g. 0, 0.1, 0.1005 etc. If you make them too close, it will result in z-fighting. It’s probably wise to stick to a few clear choices though, like 0, 0.5, 1.0. You could also make a custom render_script and redefine the interval to something you prefer, search for set_projection in the rendering manual to see how it works.

2 Likes

Well, I’ve done it now!

For the record it was a question of changing
render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1, 1))
to
render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), 0, 10))

Simple.

…okay, next question: where is the nodes folder? Is that best way of creating a large black shape that will fade in when loading a new scene (…and fade out when a new collection is loaded?)

There’s a couple of different posts discussing how to do different screen transitions:



Thanks for the homework. britzl.

Hey, here’s another question. How can I unload the initial collection? My initial collection as specified in the game project is called level1. From there, I can succesfully load the menu collection and it appears on the screen. But from there, I am unable to unload the “level1” collection. The appropriate code returns

ERROR:GAMESYS: The collection /main/level1.collectionc could not be disabled since it is not enabled. Message ‘disable’ sent from menu:/go#script to menu:/go#ll1.
ERROR:GAMESYS: The collection /main/level1.collectionc could not be finalized since it was never initialized. Message ‘final’ sent from menu:/go#script to menu:/go#ll1.
ERROR:GAMESYS: The collection /main/level1.collectionc could not be unloaded since it was never loaded. Message ‘unload’ sent from menu:/go#script to menu:/go#ll1.

any advice?

The initial collection (main_collection in game.project) can’t be unloaded. It’s the main entry point of your game. You can instead create a tiny collection that serves as loader and possibly also menu, which in turn would load level1, and set that as main_collection. This is how most released games would work anyway, you want the game to boot as quickly as possible so you can show light game graphics (progress bar) whenever heavier assets need to be loaded.
It’s a really good idea to let your levels remain functional stand-alone, meaning that you can test them by setting the level as main_collection (like your current setup), so you don’t have to click your way through menu systems every time while working.

1 Like

Just as @Ragnar_Svensson says you cannot unload the main collection. For a game such as Blossom Blast we use a tiny loader collection containing the King splash logo as main collection. The loader collection has one collection proxy to a main/controller collection, which in turn has two proxies: one for the map and menus and one for the actual game itself. The main/controller collection then loads/unloads menu and game depending on the actions of the user. I have an example quite similar to this setup here: https://github.com/britzl/publicexamples/tree/master/examples/menu_and_game

1 Like

Thank you @britzl and @Ragnar_Svensson.
I have sort it now.

One thing that confused me for a long time is that

This code doesn’t work

function init(self)
  msg.post("loaderobject#introductionproxy", "load")
  print("loading")
end
  
function on_message(self, message_id, message, sender)
        if message_id == hash("proxy_loaded") then
        print("loaded")
               msg.post(sender, "init")
               msg.post(sender, "enable")
               end
end   


function on_message(self, message_id, message, sender)
    -- Add message-handling code here
    -- Remove this function if not needed
end

But this code does. I guess the reason will be obvious to most people but for a beginner it’s not intuitive.

function init(self)
  msg.post("loaderobject#introductionproxy", "load")
  print("loading")
end
  
function on_message(self, message_id, message, sender)
        if message_id == hash("proxy_loaded") then
        print("loaded")
               msg.post(sender, "init")
               msg.post(sender, "enable")
               end
end   

In the first code snippet you are actually overwriting the previously declared on_message function. Think of it like this:

local a = 1
local a = 2

print(a) -- will print 2

or more specific for this case:

local on_message = function() return 1 end
local on_message = function() return 2 end

print(on_message()) -- will also print 2

or even more specific:

function on_message()
    return 1
end
function on_message()
    return 2
end

print(on_message()) -- will still print 2

If you specify the a new function with the same name as a previously declared it will simply overwrite the old one. :slight_smile:

4 Likes