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

Quick questions about Gideros&Lua

1810121314

Comments

  • In Google Play Dev Console there's message "To add in-app products, you need to add the BILLING permission to your APK".

    There's no 'billing permission' in Gideros' 'Require' plugin.
    It sets automatically when we include 'IAP' plugin?
    image
    IAP.jpg
    998 x 398 - 65K
    IAP.jpg 65.3K
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • Yes, then upload your apk as an alpha, beta or whatever and it should then be enabled, you add the IAP in the play console, then add it to your Lua code.

    Likes: Apollo14

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited August 2018
    Guys, how can we make colored PNG picture black-and-white? (after adding it to stage)
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • piepie Member
    @Apollo14 I think a shader is the only option, I have not tested setColorTransform() but I suppose it would render the bitmap as a black square. Could be worth a try though :)

    Likes: Apollo14

    +1 -1 (+1 / -0 )Share on Facebook
  • maybe there is an appropriate blending mode to achieve this, but i don't know which if any.
  • olegoleg Member
    keszegh said:

    maybe there is an appropriate blending mode to achieve this, but i don't know which if any.

    1-Sprite.ZERO,
    2-Sprite.ONE,
    3-Sprite.SRC_COLOR,
    4-Sprite.ONE_MINUS_SRC_COLOR,
    5-Sprite.DST_COLOR,
    6-Sprite.ONE_MINUS_DST_COLOR,
    7-Sprite.SRC_ALPHA,
    8-Sprite.ONE_MINUS_SRC_ALPHA,
    9-Sprite.DST_ALPHA,
    10-Sprite.ONE_MINUS_DST_ALPHA,
    11-Sprite.SRC_ALPHA_SATURATE
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • piepie Member
    great hgy29! I totally forgot about that :)
    I feel there is a need to give an order to all these useful examples and snippets!
  • olegoleg Member
    Apollo14 said:

    Guys, how can we make colored PNG picture black-and-white? (after adding it to stage)

    just make a black and white copy of png and upload it to the project,

    Likes: Apollo14

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+1 / -0 )Share on Facebook
  • oleg said:

    Apollo14 said:

    Guys, how can we make colored PNG picture black-and-white? (after adding it to stage)

    just make a black and white copy of png and upload it to the project,
    that's really good and simple way, I'm surprised I didn't think about this method :smile:
    though in some cases just applying shader could be more convenient
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • olegoleg Member

    @Apollo14
    hgy29 answered while I was writing, and I did not see his answer

    Likes: Apollo14

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+1 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited September 2018
    Why in the classic 'Button.lua' class it adds/removes bitmaps to stage every time?
    Isn't it better to just use "setTexture"?

    Original code inside Button.lua:
    if state then
    		if self:contains(self.upState) then
    			self:removeChild(self.upState)
    		end
     
    		if not self:contains(self.downState) then
    			self:addChild(self.downState)
    		end
    	else--...
    My guess:
    local btnTextureNormal,btnTexturePushed=Texture.new("pics/btn_normal.png",true),Texture.new("pics/btn_pushed.png",true)
    local btn=Bitmap.new(btnTextureNormal)
    stage:addChild(btn)
     
    stage:addEventListener(Event.TOUCHES_BEGIN, function()
    	btn:setTexture(btnTexturePushed)
    end)
     
    stage:addEventListener(Event.TOUCHES_END, function()
    	btn:setTexture(btnTextureNormal)
    end)
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • "Isn't it better to just use "setTexture"?"

    I think the answer is yes, most of the time.

    My custom Button class still uses sprites and setVisible() instead. This allows me to use movie clips, or custom classes, for each button state.

    If that's not needed, bitmap:setTextureRegion() is probably the most efficient.

    Likes: Apollo14, antix

    My Gideros games: www.totebo.com
    +1 -1 (+2 / -0 )Share on Facebook
  • Guys, when we work with classes, we should avoid attaching objects to 'self'? (make them all local wherever we can?)
    function StartScene:init()
    	self.bg=Bitmap.new(Texture.new("pics/background.png",true))
    	self:addChild(self.bg)
     
    	self.iconCoin=Bitmap.new(Texture.new("pics/icon_coin.png",true))
    	self:addChild(self.iconCoin)
    end
    OR:
    function StartScene:init()
    	local bg=Bitmap.new(Texture.new("pics/background.png",true))
    	self:addChild(bg)
     
    	local iconCoin=Bitmap.new(Texture.new("pics/icon_coin.png",true))
    	self:addChild(iconCoin)
    end
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • totebototebo Member
    edited September 2018
    Yes, if possible, because local variables are a lot faster. A couple of things to note:

    - You can make local variables scoped to the class if you declare them outside the functions. By doing this at the top of the document all methods can share the var.
    - If you do use class scoped local vars, they will be shared by all instances. This might not be desirable, in which case you have to use self.var.

    Likes: Apollo14

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • totebo said:

    Yes, if possible, because local variables are a lot faster. A couple of things to note:

    - You can make local variables scoped to the class if you declare them outside the functions. By doing this at the top of the document all methods can share the var.
    - If you do use class scoped local vars, they will be shared by all instances. This might not be desirable, in which case you have to use self.var.

    wow this is exactly what I wanted to know, many thanks!

    Likes: totebo

    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
    +1 -1 (+1 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited September 2018
    Guys how to show numeric keyboard?
    Either my syntax is incorrect, or there's a bug:
    newInputDialog = TextInputDialog.new("my title", "my message", "some text", "Cancel", "OK")
     
    newInputDialog:setInputType(NUMBER) --crashes app
    newInputDialog:setInputType(TextInputDialog.NUMBER) --doesn't show numeric keyboard when I call newInputDialog:setInputType:show()
     
    newInputDialog:addEventListener(Event.COMPLETE, function() print "number was entered" end)
     
    self:addEventListener(Event.TOUCHES_END, function(event)
    	if userNumButton:hitTestPoint(event.touch.x,event.touch.y) then
    		newInputDialog:show()
    	end
    end)
    image
    numInputDialog.jpg
    360 x 640 - 46K
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • @Apollo14 try TextInputDialog.PHONE as a parameter to newInputDialog:setInputType()
    +1 -1 (+2 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited September 2018
    I've created 'StartScene.lua', loaded it with SceneManager as usual.
    I don't get why I can't access object 'StartScene.bg' from outside of StartScene:init() function?
    StartScene = Core.class(Sprite)
     
    function StartScene:init()
    	self.bg=Bitmap.new(Texture.new("pics/background.png",true))
    	self:addChild(self.bg)
     
    	self.iconCoin=Bitmap.new(Texture.new("pics/icon_coin.png",true))
    	self:addChild(self.iconCoin)
    end
     
    function StartScene:setObjectsVisible(param)
    	if param==false then
    		self.bg:setVisible(false)
    	elseif param==true then
    		self.bg:setVisible(true)
    		self.iconCoin:setVisible(true)
    	end
    end
     
    --this function doesn't work when I call it later:
    StartScene:setObjectsVisible(false)
    --StartScene.lua:201: attempt to index field 'bg' (a nil value)
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • hgy29hgy29 Maintainer
    You need to call the instance, not the class
  • hgy29 said:

    You need to call the instance, not the class

    Thx! Can you please share a code snippet? (I didn't get exactly how to do it)

    something like that?
    StartScene = Core.class(Sprite)
    local bg, iconCoin
     
    function StartScene:init()
    	bg=Bitmap.new(Texture.new("pics/background.png",true))
    	self:addChild(bg)
     
    	iconCoin=Bitmap.new(Texture.new("pics/icon_coin.png",true))
    	self:addChild(iconCoin)
    end
     
    function StartScene:setObjectsVisible(param)
    	if param==false then
    		bg:setVisible(false)
    		iconCoin:setVisible(false)
    	elseif param==true then
    		bg:setVisible(true)
    		iconCoin:setVisible(true)
    	end
    end
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • hgy29hgy29 Maintainer

    scene=StartScene.new()
    scene:setObjectsVisible(false)
  • Yes, but this is my scene class, I don't call directly 'StartScene.new()', it is used in Scene Manager
    sceneManager = SceneManager.new({
    	["StartScene"] = StartScene,
    })
    Is it possible somehow to access 'StartScene.bg' object?
    Or I should stick to the solution with local vars scoped to the class?
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • piepie Member
    edited September 2018
    If I recall correctly, I think that you can use sceneManager.scene1.bg

    bg has to be a property of your scene class, and your scene has to be the current one (has to be loaded by sceneManager)

    Likes: Apollo14

    +1 -1 (+1 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited September 2018
    pie said:

    If I recall correctly, I think that you can use sceneManager.scene1.bg

    bg has to be a property of your scene class, and your scene has to be the current one (has to be loaded by sceneManager)

    it doesn't work :'(
    StartScene.lua:201: attempt to index field 'startScene' (a nil value)
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • piepie Member
    edited September 2018
    @Apollo14 wait, don't be sad :) I feel there is something wrong in your implementation if you get the name of the scene in the error output. It may still work:

    Assuming your sceneManager instance is called SM and you have opened your startScene there:

    SM.scene1.bg should return something (still if I am not wrong, I can't check how I did it right now.. ) ;)

    If the code you provided is your actual code, and you already loaded "startScene" there, it should be:

    sceneManager.scene1:SetObjectsVisible (false)

    And of course, to make it work you should have access to the sceneManager instance (which is the parent of your loaded scene): so it should be either a global object or if it's a local object you have to call it from within the same scope.

    P.s. however you could also check sceneManager source to fix naming: it seems to me that it used self.scene1 and self.scene2 to store scenes and apply the transitions.

  • author of Zerobrane Studio mentioned that whole Zerobrane program was made using Lua
    Do you know what IDE is used for developing and compiling windows software like that? (using Lua)
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • Apollo14 said:


    Do you know what IDE is used for developing and compiling windows software like that? (using Lua)

    для простих задач, я використовую AutoIt -це не Lua, але теж дуже простий скрипт

    Likes: Apollo14

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+1 / -0 )Share on Facebook
  • Maybe @paulclinger could shed some light on this :)

    Lua really needs a decent IDE like Visual Studio with drag and drop GUI creation.
Sign In or Register to comment.