Here is my first personal game with Defold: Gold Rush
It is based upon the side scroller tutorial. I tried to redo everything myself with free assets. It’s a little rough and many things need to be polished. The difficulty is quite challenging.
I still haven’t looked at a way to reload the game when game over occurs nor have I put any message or title screen. This will be the next challenge for me.
Should I put the game on the assets portal or should I wait for a more polished version to publish it there?
Haha, wow, I thought there was something wrong with my browser. So tiny!
Reloading is pretty simple. If you put your game stuff into a collection other than “main”, then hook it up to your main collection with a Collection Proxy, then you can unload and reload it whenever you want. The simplest way is to just let people press “R” (or something) to reload. (so you don’t have to make a menu or whatnot.)
@britzl: Yes, I will do that soon. Original size is 160*144 so, how much zoom should I use? The graphics are from Grafxkid. I liked his style so I based the game upon some of his graphics.
@ross.grams: Yes I thought that Collection Proxies would do the trick but I need to study a little more to add a title screen too. I’m currently working on that.
To enable resizing, I tried this but it didn’t worked:
msg.post("@render:", "use_fixed_fit_projection", { near = -1, far = 1, zoom = 3 })
By using fixed_fit_projection, I wanted to prevent stretching. and since it could show beyond border of the screen (where I spawn objects), I decided to add a black tilemap as a frame mask to the screen.
Correct. Fixed fit projection will maintain aspect ratio and scale the game to fit the window.
What you want is the Fixed projection where you can specify your own zoom. The window will maintain aspect ratio and always keep the content zoomed to the level you specify.
Exactly! I disabled the collision shape and it no longer hits twice. I stille have some tweaks to do so I won’t update the released game until I’m done. Do you think it’s a bad move?
I updated the game with some new things. Clouds, title and exploding bombs. Very simple stuff but I think it helps to better enjoy the game. I still haven’t found how to restart the game. I tried unloading the collection proxy when pressing escape but my code doesn’t work.
Restarting the game is simple. All you need is just another collection. I generally like to call it controller.
Change the name of the collection to controller too. Then go to game.project and set the default collection as the controller
In the controller collection, add a game object called proxies, and add a collection proxy called main. Assign the main collection to its target.
Next, create a script called controller.
In the init function, ask the collection proxy to load the proxies#main collection proxy, which we created above. This will load the main collection on start up.
Then, in the on_message function, say that
if message_id == hash("reload_scene") then --never put reload here , it will cause an error.
load() --call a function load
end
Then finally in the load function, unload the currently loaded main collection…(pause)…and then load it again, as we did in the init function.
And then, when you want to reload the scene, just say.
Thanks.
Actually, I already did something like that. I have a main collection with a game object called loader holding the different collections (actually, scenes or screens) proxies.
I then use this script based upon documentation about proxies:
function init(self)
self.current_screen = "title"
msg.post("#" .. self.current_screen .. "_proxy", "load")
end
function on_message(self, message_id, message, sender)
if message_id == hash("proxy_loaded") then
-- New world is loaded. Init and enable it.
msg.post(sender, "init")
msg.post(sender, "enable")
end
if message_id == hash("switch_to_game") then
msg.post("#" .. self.current_screen .. "_proxy", "disable")
msg.post("#" .. self.current_screen .. "_proxy", "final")
msg.post("#" .. self.current_screen .. "_proxy", "unload")
self.current_screen = "game"
msg.post("#" .. self.current_screen .. "_proxy", "load")
end
end
As you can see, there are (for now) two proxies. One called “title_proxy” that loads at startup of the game and one called “game_proxy” that loads when the message “switch_to_game” is received. This is sent from the “title” collection when the player pushes an input.
I tried this on “on_input” function but it didn’t worked:
function on_input(self, action_id, action)
if action_id == hash("escape") then
msg.post("#" .. self.current_screen .. "_proxy", "disable")
msg.post("#" .. self.current_screen .. "_proxy", "final")
msg.post("#" .. self.current_screen .. "_proxy", "unload")
self.current_screen = "game"
msg.post("#" .. self.current_screen .. "_proxy", "load")
end
end
The problem comes from the fact that the key press sends a message each frame. It seems to hinder the loading of the collection.