Draw at touch with scale messed up [ANSWERED]

Why doesn’t this draw at my finger?

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")

-- This function gets called once every frame
function draw()
    -- This sets the background color to black
    background(76, 255, 0, 255)

    -- Do your drawing here
    sprite("Planet Cute:Star", CurrentTouch.x, CurrentTouch.y)


Because the touch coordinates are always with respect to screen coordinates, that’s why. So they aren’t adjusted for scale (or rotate, or teanslate).

Because you scaled it? You’re looking for a better explanation.

Because touch doesn’t scale. So when you touch at, say, 500, 500, and then draw with scale(2), you draw at 1000, 1000, which is off screen. if you run what you have above and touch near the “reset” button - there’s your star.

to do what I suspect you want - to draw a double-sized star - you’d go:

transform(CurrentTouch.x, CurrentTouch.y)
sprite("Planet Cute:Star")

Which I read in my mind as “Move to the touch, get bigger, draw”.

What you’re doing originally is “Get bigger, move to the touch (but far, because we’re big), then draw”.

AHHG. I get it. I knew about transform, but I was wondering if thre was an easier way to do it.

Is there a function to map device coordinates to transformed view coordinates (and vice versa)? If not, that would be a good addition.

I saw some post a homegrown one but can’t find it.

If you track scale in a global variable you can use it as a multiplier in touch.

@Nat that’s a really good suggestion. We’ll try adding something that uses the current matrix to transform and project the touch.

Sounds cool.

I just said to divide the coordinates you want by the scale. Why didn’t I think of it before?

That works here - but if you’ve scaled, and transformed, and rotated, maybe multiple times - by providing a translator that does what Simeon says (!), you’ll be able to undo (or redo?) all of them. Handy!

I agree.