snap to grid

Hi everbody,

first some congratulations to ansca: so far i really like Corona and Lua as supporting language as well! I hope your business modell and the way to get the applications onto our iphones will fit my situation as well. If yes, you’ll see me around here for a long time to come ;-).

Now to my questions to anybody who might have tried anything like that already:
I’m developing a 2d card/board game where you stick images onto cards. These image+card combinations are new images from a player point of view as he couldn’t seperate them anymore. So far i use groups of images to move them around. Maybe someone of you know a better solution for it, but that’s not my actual question.
I need a mechanism while i drag one image around the screen that fits this image onto a predefined grid or onto a fixed position onto another image.

If you understood what i am looking for ;-), does one of you has any hint for me how i should solve this problem?

Looking forward to any solutions or ideas

Best and thanks in advance
Jens [import]uid: 1919 topic_id: 107 reply_id: 300107[/import]

I’m sure you could code it to do something like photoshop does, but it would probably be easier to just detect when you’ve dragged it to a certain location, and then when you let go, it figures out what rectangle you’ve dragged it over and centers it up that way.

if rect.x == some range of corrdinates then
groupofcoolpictures.x == whatever you want
end

something along those lines for y as well? [import]uid: 5 topic_id: 107 reply_id: 72[/import]

Hmmm…
…yes, that could do it, as i know which position has what coordinates, so i could check something alike for various slots that the new image should fit too.

I’ll give it a try. Thanks for the idea.

Does anybody know if there some kind of image collision detection that i could as alternative? [import]uid: 1919 topic_id: 107 reply_id: 73[/import]

You might be able to use the bouncing ball from Animation1 as a starting place:

local function animate(event)
xpos = xpos + ( xspeed * xdirection );
ypos = ypos + ( yspeed * ydirection );

if (xpos > display.stageWidth - radius or xpos < radius) then
xdirection = xdirection * -1;
end
if (ypos > display.stageHeight - radius or ypos < radius) then
ydirection = ydirection * -1;
end

circle:translate( xpos - circle.x, ypos - circle.y)
end

instead of using “display.stageWidth” you could probably substitute another value or function there, I mean, display.stageWidth just returns the value of the width of the screen, 320. You could replace display.stageWidth with 10 if you wanted to. Just an idea. [import]uid: 5 topic_id: 107 reply_id: 74[/import]