Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Quick questions about Gideros&Lua - Page 4 - Gideros Forum

Quick questions about Gideros&Lua

12467

Comments

  • hgy29hgy29 Maintainer
    1) To use Screen (that is windows) you first need to create them:
    screen=Screen.new(0)
    2)
    application:setKeyboardVisibility(true)
    should pop up the native keyboard and return true if it was able to do so.
    3) Seems like you forgot to specify the arg to Core.random[Seed], which specify which random generator to use. Basically there is guarantee that lua math.random will produce the same random sequence for a given seed on all platforms, as it relies on OS provided random functions. Core.random() guarantees this.

    Likes: SinisterSoft

    +1 -1 (+1 / -0 ) Share on Facebook
  • THX @hgy29 !
    1) What is the actual purpose of "Screen.new"? (I've tried to search, but didn't find any info about it)
    Is it made for managing scenes or layers?

    3) Which arguments should be added?
    When I test this code, results are always randomized, there's no consistancy:
    function onMouseDownFunc(event)
    print("random num:",Core.random(10,200,300))
    end
     
    stage:addEventListener(Event.MOUSE_DOWN, onMouseDownFunc)
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
  • The Lua built-in random number generator may produce the same sequence on one device (if you set the seed), but on a different os or brand of device it may produce a different sequence. The core version will produce the same sequence on all devices - if you set the seed.
  • SinisterSoftSinisterSoft Maintainer
    edited February 20
    Core.randomSeed(algorithm to use[,fixed seed])
    Core.random(algorithm to use[,start][,end])
    Currently the algorithm to use should be 0

    Your example corrected:
    Core.randomSeed(0,10)
    randNum = Core.random(0,1,10)
    print(randNum)

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
  • hgy29hgy29 Maintainer
    Screen.new can be used on desktop only to open additional windows

    Likes: antix

    +1 -1 (+1 / -0 ) Share on Facebook
  • Thx guys!!

    Guys, I'm trying to write a function:
    I have 7 scenes: 'day1.lua', 'day2.lua'...'day7.lua'
    And 7 pics: 'day1pic.png', 'day2pic.png'...'day7pic.png'

    I've added function to my 'init.lua':
    function addYantra(picName, parent)
    	yantra = Bitmap.new(yantrasPack:getTextureRegion(picName..".png"))
    	yantra:setAnchorPoint(.5,.5)
    	yantra:setPosition(centerX,appH/3*2)
    	parent:addChild(yantra)
    print(parent) --it prints "table: 0x7f980e0c28"
    end
    In every scene file I add:
    day1 = gideros.class(Sprite)
     
    function day1:init()
    	addYantra("day1pic",self)
    end
    It works ok.
    Can number of arguments be reduced to one? Like:
    function day1:init()
    	addYantra(self)
    end
    How to transform argument 'self' into the string with the name of the class?
    "table: 0x7f980e0c28" --> "day1"
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
  • The class is a table so it prints table. If each class had a name variable you could just use print(parent.name)

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
  • if you use zerobrane then it has some nice looking printing/watching capabilities for tables.

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
  • Apollo14Apollo14 Member
    edited February 21
    Guys is it inevitable that TTFont is lagging in my case? Or I can do something to optimize it? Maybe pre-load it on scenes somehow?

    Inside 'init.lua' I have:
    smallFont = TTFont.new("fonts/segoeuil.ttf", 14, false)
    function addTextWrap(parent)
    	local str="Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nSed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    	local planetText = TextWrap.new(str, 300, "left", 5, smallFont)
    	planetText:setAnchorPoint(.5,.5)
    	planetText:setPosition(centerX, 200)
    	parent:addChild(planetText)
    end
    Inside scene file 'day4.lua' I have:
    day4 = gideros.class(Sprite)
     
    function day4:init()
    	addTextWrap(self)
    end
    On PC it doesn't lag at all, but on Android Player it slightly lags when Scene Manager loads the scene 'day4' with TTFont. Scenes without TTFont don't lag.
    'segoeuil.ttf' weights 790kb :s
    p. s. my android device has decent perfomance (xiaomi note 4x)
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
  • olegoleg Member
    and so tried?
    smallFont = TTFont.new("fonts/segoeuil.ttf", 14, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM-1234567890")

    Likes: Apollo14, antix

    +1 -1 (+2 / -0 ) Share on Facebook
  • oleg said:

    and so tried?

    smallFont = TTFont.new("fonts/segoeuil.ttf", 14, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM-1234567890")
    Wow! Now it works perfectly well! THX! :)
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
  • hgy29hgy29 Maintainer
    Or just use “” (empty string) instead of your char set to let gideros figure out by itself

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited February 21
    I do this:
    local chrs=""
    fonts={{file="zombie.ttf",sizeMult=1.0},
         {file="cyrillic.ttf",sizeMult=1.0},
         {file="japanese.ttf",sizeMult=0.8},
         {file="arabic.ttf",sizeMult=1.0}}
    smallFont=TTFont.new(fonts,33,chrs,3)
    font=TTFont.new(fonts,66,chrs,3)
    fontLarge=TTFont.new(fonts,132,chrs,3)
    That will automatically try add characters from the fonts in turn (until it gives up) as they are needed. The '3' gives a nice smoothing to the font. The Japanese font was a little large compared to the others so the size is set slightly smaller.

    Likes: oleg, Apollo14

    +1 -1 (+2 / -0 ) Share on Facebook
  • Apollo14Apollo14 Member
    edited February 23
    Guys I'm curious why Gideros' installation size is so big compared to other frameworks and even engines? 741mb is pretty huge.

    It's very intriguing - what is there so huge inside Gideros that is not inside other engines&frameworks.
    love2d weights 3mb, Corona is 83mb, Defold is 300+mb, Godot is 20, etc.
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
  • hgy29hgy29 Maintainer
    The big size is mostly due to all precompiled export templates and players gideros has: libs with associated debugging information can be above 100MB per platform. They are particularly huge on windows phone, windows 8, iOS and Apple TV. Take a the size of players and templates folders in your gideros installation, you will see what I mean.

    Likes: Apollo14, antix

    +1 -1 (+2 / -0 ) Share on Facebook
  • I think it would be best (long term) if the template folders were downloaded on demand. That way they could be updated independently of each other and the main editor/texture packer, etc.
  • Guys, how rpg-style dialogue class can be made?
    (when text appears symbol-by-symbol)

    Did somebody make it before?
    rpg-dialogue.gif
    585 x 423 - 192K
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
  • uh, I've made primitive rpg-dialogue:
    but I'm not sure guys if it is the most optimal way? :D
    dialogue1 = "Hello my friend! How are you?"
     
    displayDialogue = TextField.new(nil, "")
    displayDialogue:setPosition(200,200)
    stage:addChild(displayDialogue)
     
    i = 0
    function onNewTimerFunc()
    	i+=1
    	if i <= #dialogue1 then
    	displayDialogue:setText(displayDialogue:getText()..string.sub(dialogue1,i,i))
    	else
    	--do some stuff after dialogue completed
    	print("completed!")
    	newTimer:stop()
    	end
    end
     
    newTimer = Timer.new(100,0)
    newTimer:addEventListener(Event.TIMER, onNewTimerFunc, newTimer)
    newTimer:start()</pre>

    Likes: oleg

    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    +1 -1 (+1 / -0 ) Share on Facebook
  • antixantix Member
    edited February 24
    @Apollo14, here is a VERY quick and DIRTY example of one possible solution..
    font = Font.getDefault()
     
    brush = TextField.new(font, "A")
    brush:setTextColor(0x774411)
     
    local canvas = RenderTarget.new(160, 128)
    canvas:clear(0x77bbff, 1)
    textBox = Bitmap.new(canvas)
    textBox.width = 160
    textBox.height = 128
    textBox.speed = 0.15 -- speed that the box plops out text
    textBox.counter = 0 -- used for timing text plops
    textBox.pos = 0 -- start at 0
    textBox.x = 0
    textBox.y = font:getAscender()
    textBox.done = false
    textBox.text = "Well this is some text. When the cursor exceeds the width of the container it should wrap but will be very messy. Here ends the lesson <img class="emoji" src="/forum/resources/emoji/lol.png" title=":D" alt=":D" height="20" />"
     
    function onEnterFrame(e)
      local dt = e.deltaTime
     
      if not textBox.done then
        local counter = textBox.counter + dt
        if counter >= textBox.speed then
          counter = counter - textBox.speed -- reset counter
          print("boo")
          local x, y = textBox.x, textBox.y
    	  print(x, y)
          local pos = textBox.pos + 1 -- increment character
          if pos > #textBox.text then
            textBox.done = true
          else
            textBox.pos = pos
    		print(textBox.pos)
            local char = textBox.text:sub(pos, pos) -- next character in string
            brush:setText(char) -- brush text set
            local charWidth = font:getAdvanceX(char) -- width of current char
            if x + charWidth > textBox.width then
              x = 0 -- wrap line
              y = y + font:getAscender()
            end
            brush:setPosition(x, y) -- position brush
            canvas:draw(brush) -- print the new char into the canvas
     
            textBox.x, textBox.y = x + charWidth, y -- save x and y
          end
        end
        textBox.counter = counter
      end
    end
    stage:addChild(textBox)
     
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
    So basically we use a RenderTarget as our bitmaps texture. This means we can draw into the RenderTarget and it gets updated in realtime on the screen. Then we just make our way through the text char by char and position/draw it to the RenderTarget until we are done.

    If you are using a fixed width font then you can use formatting to ensure it doesn't wrap in the middle of a word.

    It could be greatly enhanced by making it's own class but it's 11pm here and I am tired ;)

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
  • Guys, if I need to create 7 objects (pixel1, pixel2, pixel3, etc.), what is the correct syntax?
    for i=1,7 do
    local pixel..i = Pixel.new(blackColor,.1,appW,42) --'pixel..i' obviously doesn't work
    self:addChild(pixel..i)
    end
    Or it can be done only with array?
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
  • antixantix Member
    edited February 25
    @Apollo14 it all depends on how you wish to use them. the original Pixel class was very good and it still is but now there are two ways to create a Pixel
    1. As a rectangular colored shape.
    2. As a rectangle with an image mashed inside it.
    You can opt to add the pixels to a table...
    -- create pixels as elements in a Table
    local pixels = {}
     
    for i = 1, 7 do
      local pixel = Pixel.new(blackColor, 0.10, appW, 42)
      pixels[#pixels + 1] = pixel
      self:addChild(pixel)
    end
     
    -- to iterate through the pixels using this method..
    for i = #pixels, 1, -1 do
      local pixel = pixels[i]
      -- do stuff with pixel
    end
    Or hang them off a Sprite...
    -- create pixels as children of a Sprite
    local pixels = Sprite.new()
     
    for i = 1, 7 do
      pixels:addchild(Pixel.new(blackColor, 0.10, appW, 42))
    end
    self:addChild(pixels)
     
    -- to iterate through the pixels using this method..
    for i = pixels:getnumChildren(), 1, -1 do
      local pixel = pixels:getChildAt(i)
      -- do stuff with pixel
    end

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
  • antix said:

    @Apollo14, here is a VERY quick and DIRTY example of one possible solution..
    ...
    It could be greatly enhanced by making it's own class but it's 11pm here and I am tired ;)

    @antix would you be so kind to create a class for RPG-style dialogues when you'll have some free time? I think it could be extremely handy, because dialogues make game very cute :)
    Thanks! :smiley:
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
  • @Apollo14 Sorry dude, I'm really bogged down with the website upgrade which has meant I'm not working on my book or own games.

    One of the example games in my book (a puzzle based platformer) will need such a system though, so you never know ;)

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
  • Apollo14Apollo14 Member
    Guys, is there a shorter way to write such comparisons in Lua syntax?
    currLocale = application:getLocale()
    if currLocale == 'de_DE' or currLocale  == 'de_AT' or currLocale  == 'de_CH' or currLocale  == 'de_LU' then
    	--do stuff
    end
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
  • snookssnooks Member
    edited March 2
    Apollo14 said:

    Guys, is there a shorter way to write such comparisons in Lua syntax?

    currLocale = application:getLocale()
    if currLocale == 'de_DE' or currLocale  == 'de_AT' or currLocale  == 'de_CH' or currLocale  == 'de_LU' then
    	--do stuff
    end
    Yup, you can check a substring....
    if currLocale:sub(1, 3) == "de_" then
      -- do cool stuff
    end
     
    -- and do something like...
     
    local localeActions = {
      ["de_"] = function() print("Ja!")  end,
      ["en_"] = function() print("Yes!") end,
      ["fr_"] = function() print("Oui!") end
    }
     
    localeActions[currLocale:sub(1, 3)]()

    Likes: Apollo14, antix

    +1 -1 (+2 / -0 ) Share on Facebook
  • Apollo14Apollo14 Member
    edited March 2
    Guys is there a way to create Wallpaper apps in Gideros?
    Maybe something like this https://github.com/scottrules44/wallpaper-demo/blob/master/main.lua (beer sdk)
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
  • antixantix Member
    @Apollo14 only if you were to create a plugin that allowed that.
  • antixantix Member
    @oleg cool, it can't be done in Gideros though :)
  • SinisterSoftSinisterSoft Maintainer
    @Apollo14 There was a lag in one of the TTFont combinations (when you supply an empty string) - that has now been fixed in either the latest release or the upcoming 2018.3 release (I can't remember).

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
Sign In or Register to comment.