Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Next problem with button
Started by strusinski.adam Nov 28 2019 03:21 AM

3 replies to this topic
button
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

strusinski.adam

[GLOBAL: userInfoPane.html]
strusinski.adam
  • Observer

  • 6 posts
  • Corona SDK

Hello everyone, I have another problem with the button. I am trying to make the button (kprzycisk) inactive or completely remove after pressing the button. I used the function removeSelf and  isVisible = false probably everywhere, but either nothing happens or I had an error. Could someone advise me where to add and what function to make the button  kprzycisk remove after use. If this is the basis of knowledge and my question is a bit silly I am sorry

 

local widget = require("widget")
local physics = require ("physics")
physics.start()
physics.setGravity(0,0)


Punkty = 0
PunktyTekst = display.newText("Punkty = " .. Punkty, 45, -15, native.systemFont, 15)



local function gprzyciskf (e)
Punkty = Punkty + 1
PunktyTekst.text = "Punkty =" .. Punkty
end

local gprzycisk = widget.newButton{
onRelease = gprzyciskf,
defaultFile = "Punkt.png",
width = 100,
height = 100,
}
gprzycisk.x = display.contentCenterX
gprzycisk.y = display.contentCenterY



local function kprzyciskf (e)
if Punkty >= 5 then
Punkty = Punkty - 5
PunktyTekst.text = "Punkty =" .. Punkty
local karabin = display.newImageRect("karabin.png", 50, 25)
karabin.y = display.contentCenterY
karabin.x = 30

local function autostrzal()
local pocisk = display.newImageRect("pocisk.png", 30, 30)
pocisk.x = karabin.x
pocisk.y = karabin.y
physics.addBody(pocisk, "dynamic")
transition.to( pocisk, { x= 135, time=200,
onComplete = function() display.remove(pocisk)
   

Punkty = Punkty + 1
PunktyTekst.text = "Punkty =" .. Punkty

end}
        )
end

timer.performWithDelay( 2000, autostrzal, -1 )
end
end


local kprzycisk = widget.newButton{
onRelease = kprzyciskf,
height = 50,
width = 50,
defaultFile = "orb2.png",

}
kprzycisk.x = 275
kprzycisk.y = -10

 



[TOPIC: post.html]
#2

pixec

[GLOBAL: userInfoPane.html]
pixec
  • Enthusiast

  • 50 posts
  • Corona SDK

Format your code, jeez! :DD

[TOPIC: post.html]
#3

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 663 posts
  • Corona SDK

@strusinski

 

You can use the "<>" button above to format your code or use [ ]  and [/] with "lua" inside - see the "Post Formatting Tips" below.  Often, if your code is unformatted your post will be ignored.

 

You need a way to reference your button after the onRelease event.  Trying using e.target to identify and remove the button that triggered the onRelease

local function kprzyciskf (e)
    local button = e.target  -- identify the button
    display.remove(button) ; button = nil -- remove the button
    -- whatever else you want to do
end



[TOPIC: post.html]
#4

strusinski.adam

[GLOBAL: userInfoPane.html]
strusinski.adam
  • Observer

  • 6 posts
  • Corona SDK

thank you for the advice and solution of the problem! :)




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: button