Animated controls

msnawemsnawe Posts: 2Member
edited May 23 in GUI

I am new to godot so learning how to use the various nodes available on a first projet.

I am planning to make a simple game consisting of several cards placed face down. Then choosing cards to find the matching pairs. then place new cards face down and play again.

To make it easier, I use Texture buttons for the cards. (would you use something else?) . So I start back loading the back cover texture on all the cards in the grid. Then when someone clicks on a card (texture button) the signal leads to a call back function that loads the front card picture.

This works but when I have a winning pair, I would like to highlight these cards (eventually animate by blinking them or something like this). But it seems that:

  • I can not draw on the texture from the initial callback context following the press event. I can only draw from the _draw function.
  • when I move code from the callback to the _draw function, I have to resort to variables to condition whether to draw or not in _draw. is it how we are supposed to do this in Godot?
  • I can not get a timer timeout to work. The function just continues without waiting for the timeout signal.

I am using something like this (t being a timer node)

func wait (s):  
    print('wait ' + str(s))
    t.set_wait_time(s)
    t.set_one_shot(true)
    t.start()
    yield(t, "timeout")
    print('timeout ' + str(s))  

Any reason for this?

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 2,635Admin

    Welcome to the forums @msnawe!

    @msnawe said:
    I can not draw on the texture from the initial callback context following the press event. I can only draw from the _draw function.

    Yeah, unfortunately you can only draw to a CanvasItem node in the _draw function. You will need to call the update() function in your callback to trigger the _draw function being called, and then make the adjustments there.

    when I move code from the callback to the _draw function, I have to resort to variables to condition whether to draw or not in _draw. is it how we are supposed to do this in Godot?

    If it works, then I would not worry too much about it. That is how I would handle it, and if it becomes an issue later down the road, you can always refactor. I always try to get something working first, and then make it pretty and/or optimize through refactoring later once needed. I find it can be easy to fall into unnecessary premature optimization otherwise.

    I can not get a timer timeout to work. The function just continues without waiting for the timeout signal.

    I've never really used timers or gotten them to work myself. I'm sure there is a way though, and hopefully someone who knows how they work can chime in!

    The only thing I can think of that might be causing the issue is that the wait time, s is too long that it seems like nothing is happening, but given you are printing the time, I do not think this is the issue. Maybe the one-shot part is causing the issue? I would perhaps try using code like this and see if it works:

    func wait (s):  
        print('wait ' + str(s))
        t.set_wait_time(s)
        t.start()
        yield(t, "timeout")
        t.stop()
        print('timeout ' + str(s))  
    

    Also:


    This discussion was caught in the moderation queue since you have not confirmed your account yet.

    Upon creating your account you should have received an account verification email. The confirmation email may have been incorrectly flagged as spam, so please also check your spam filter. Without confirming your account, future posts may also be caught in the moderation queue. You can resend a confirmation email when you log into your account if you cannot find the first verification email.

    If you need any help, please let us know! Thanks! :smile:

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file