Howdy, Stranger!

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

Translating touches?

edited January 2012 in Questions Posts: 1,255

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?



  • 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.

  • Posts: 1,255

    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 Admin Mod
    Posts: 5,417

    @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.


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

    @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.

  • Posts: 1,255

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

  • Posts: 2,820

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

  • Posts: 1,255

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

  • Posts: 2,820

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

Sign In or Register to comment.