Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Tagged

Translating touches?
  • MarkMark
    Posts: 1,085

    I'm reworking some UI pieces so that they correctly support various display modes. The neatest way I found to do this was to use translate. That way I can just change the coordinates on one framing element and draw everything else against that boundary. It turns my UI into movable, resizable tiles that I can arrange depending on screen space.

    It works great for drawing BUT, the elements and sub-elements of the UI are heavily dependent on passing around a touch element and letting each piece respond appropriately. And I can't seem to translate touch.

    Even if I copy CurrentTouch into another touch instance, it won't let me alter the values of x and y.

    Is there any way out of this short of breaking down touch into it's values and passing them all individually?

  • Ipad41001Ipad41001
    Posts: 622

    t = vec2(touch.x, touch.y) and pass t around? Or some other {} variable that contains what you want?

    Or I don't understand the question.

  • MarkMark
    Posts: 1,085

    I can certainly pass the coordinates, but I also need to pass state, delta, and tap count.

    So what I'm asking I guess is "is there a way to translate the coordinates in the touch so I don't have to change the interface on a hundred different functions."

  • SimeonSimeon
    Posts: 3,730

    @Mark maybe you could create your own class with the exact same interface, then translate it once into that class and pass it on as if it's a regular touch.

    E.g.

    MutableTouch = class()
    
    function MutableTouch:init( touch )
        self.x = touch.x
        self.y = touch.y
        -- and so on...
    end
    
    -- Any other functions you need
    
    
  • ruilovruilov
    Posts: 446

    @Mark, I've run into this exact question before. My solution was to write a function touch.translate(dx,dy) that returns a table that has exactly the same keys as the "touch" userdata but with x and y translated. This table is treated in my code everywhere exactly as if it were a touch.

  • MarkMark
    Posts: 1,085

    Ah, cool. I knew someone would have a slick answer. Thanks!

  • ZoytZoyt
    Posts: 2,807

    Side note: Are you releasing a Cidea UI or is it only for Spritely (which I absolutely love).

  • MarkMark
    Posts: 1,085

    I'm just working on Spritely, but the bits (buttons, sliders, etc) are designed to be usable elsewhere.

  • ZoytZoyt
    Posts: 2,807

    Cool. I really liked your sliders. I forgot to mention that.