Screen size/resolution and random number for mobile?

#1

Hello everyone,

So I created a little game with Defold. I really like the process so far, and the community here is great!

However, I have a few questions and couldn’t find the answers anywhere. So here they are:

  1. What is the resolution that I should choose when I want to target my game to mobile devices? I understand that there are still some differences, like on some devices the game will show more of the background and some will not. But I the only thing I know is to change the size of the window using game.project, and that does not seem like the right way to do it. I really wish that there is a tutorial somewhere which show how to do this “the right way”. I may just completely missing some things here, if so, please help me see them! (I’m using RenderCam btw and I’m know almost nothing about this rendering stuff!)

  2. I need to generate the positions of some sprites randomly at the same time. I manage to make it work on my laptop (math.randomseed(os.clock()) but to my surprise, on my phone the positions is the same every time for every sprites. I had read about the problems with the random function in Lua, and I fixed that one (by calling math.random() a few times first) but why does this occur? And why only on the Android phone not on my laptop?

  3. Is there a way to use transitions between collections (not GUI) with Monarch? I managed to get the transitions to work with collections with GUI, but how about the collections without GUI? Because if I unload a collection and load the next one, there is a split second of a black screen before the second collection show up!

Thanks a lot!

0 Likes

#2

Using 960x640 is fine. Use a fixed fit view. The builtin render can do it, so can RenderCam and Orthographic.

Main thing you want to think about is texture size and if you want mipmaps enabled or not. So if you have a 960x640 game res with fit enabled on a much larger screen the game will look different depending on how your textures are. Defold is a 3D engine not a 2D engine so when you scale to fix larger screens usually it will look really nice if your textures are large enough.

Another important thing is mipmap bias, it’s something you set in your shader fragment program. If you do want to use mipmaps then you may want to adjust it from the default value (which is 1.0 I think).

You can resize textures during building with texture profiles so you can easily limit textures to max of 2048x2048 as long as they are in atlases. I would go with this max size for mobile.

Instead of using builtin math.random use this https://www.defold.com/community/projects/140436 or a MT Lua module.

What you want for 3 is a GUI layer on top that is a full screen fader. Fade to black (or whatever color, you could even have some nice sprites over the solid color or pattern. Make sure everything is loaded, then fade out the fader. You probably want to put your fader at like gui.set_render_order(13) so you have some levels above for cursor and anything else you want to be on top of faders always like some UI elements. (Actually atm I can’t remember if lower or higher render number is drawn first so you’ll want to test.)

Here’s an example of gui fader script https://github.com/yeqwep/Story_Table/blob/78969c28d78d494ec182d546a8a9152ca80be4dc/event/scenario_core/fade/fade.gui_script

2 Likes

#3

Thanks a lot Mr. Pkeod!

I will try to learn as much as I can about what you said as soon as possible!
It seems like there are a lot of things that I haven’t known, and a lot more questions to come :slight_smile:

Again, much appreciated!

0 Likes

#4

You could try the following by putting this on an init function when your game starts. You only have to do this once and then whenever you want to random something just use the math.random()

function init(self)
  math.randomseed(socket.gettime()) math.random()math.random()
end

So, whenever I want to random something it is working as expected.

2 Likes

#5

Very sad that your solution does not work in my case :frowning: ( Same numbers appear at the same time)

0 Likes

#6

Can you share your code? I think you’re doing something wrong.

0 Likes

#8
function init(self)
    math.randomseed(os.clock()*100000000000)
    math.random(); math.random(); math.random();
    -- math.randomseed(socket.gettime()) math.random()math.random() -- This doesn't work

    get_new_pos_random(self)
end

function get_new_pos_random(self)
    local pos_x = math.random(-1000, 1000)
    local pos_y = math.random(-1000, 1000)
    local pos_z = math.random(-1, 5)

    self.new_pos = vmath.vector3(pos_x, pos_y, pos_z)
    self.rot_deg = math.random(-359, 359)
end

What I did is I created a collection factory of this collection, and I’m trying to get 15 sprites’ positions randomly AT THE SAME TIME with:

 for i=0, 15 do 
     local sprite_id = collectionfactory.create("#sprite_factory")
 end

The above code works fine in my computer, but when I try with dmengine or bundle on an Android phone it doesn’t work. (All sprites have the same position)

0 Likes

#9

Wait, hold on, are you calling math.randomseed() from within the init() function of the created game object? math.randomseed() should be called only ONCE from a single script at startup of your application.

And you should really only do:

math.randomseed(socket.gettime()) math.random() math.random()

Don’t use os.clock() or os.time(). socket.gettime() is the most granular. And make sure to throw away the first one or two random numbers as in my snippet of code above.

3 Likes

#10

Yes, you are right!
I put math.randomseed(socket.gettime()) in the handler.script only and it works now!
Thanks a lot!

I read a lot about the camera and screen resolutions but it doesn’t seem like I’m getting anywhere. Do I need to put a camera on each collection or I just need one camera for the whole game? I hope that you could point me to somewhere or some projects that I could dive into to learn about these stuffs (I don’t know the differences between the builtin camera and RenderCam but I’m using RenderCam since it supports Perspective view)

I know I’m a totally beginner, but I really like Defold so far; and really want to gain more knowledge about the engine, so please don’t mind if my questions sound silly!

Much appreciated!

0 Likes

#11

It depends™.

If you plan to use the same view and projection for menus and in-game then a single camera is enough. If you intend to pan around in the game or use different view and projection for different parts of your game it might make sense to have multiple cameras and enabled/disable them.

1 Like