Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Function — Gideros Forum

Function

KamilolololoKamilolololo Member
edited August 2013 in General questions
Please help me guys! I have 2 functions in a class. I need a code. I want to move to the second function after a button was clicked in the first function. They are in the same class. THANKS A LOT.

Comments

  • techdojotechdojo Guru
    Accepted Answer
    Not sure how you've defined your button - but in short you need to hook into the event that's generated when the button is pressed.

    There are plenty of examples on the forum and in the gideros package that show you how to add a touch handler to a sprite to make it a button and then check to see if a press was registered within the bounds of the sprite, if it was then an event is usually generated alternatively this is the point when you should call the second function.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • @techdojo is it possible that if you clicked a button then it will transfer to another function? Please help me the code. :)
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @Kamilolololo what do you mean by transfer? Execute another function?
    MyClass = Core.class(Sprite)
     
    function MyClass:init()
        self:addEventListener(Event.MOUSE_DOWN, self.otherMethod, self)
    end
     
    function MyClass:otherMethod(e)
        if self.hitTestPoint(e.x, e.y) then
            print("executed this method on click")
        end
    end
  • @ar2rsawseen can I ask what is the purpose of Event.MOUSE_DOWN? Thank you :D
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Event.MOUSE_DOWN means it will listen to mouse down event, or when you will press down the left mouse button.

    There are also other events available: http://docs.giderosmobile.com/reference/gideros/Sprite#Sprite
  • Waaa! I don't know why it wasn't working in my code. :(
Sign In or Register to comment.