SOLVED - Sticky Dragging

Heylo,
I've got a level and the player drags it around to look around.
I dont want the player to look outside of the levels boundaries.

I used this piece of code.

1
2
3
4
5
6
7
8
9
local function drag(e)
if (e.phase == "moved") then
            if (game.x < 1 and game.x > -481) then
                game.x = e.x - touchposx
            end
            if (game.y < 1 and game.y > -321) then                
                game.y = e.y - touchposy
            end
end

Edit: my comment below only applies if you are using physics. If not, I have no clue why you are having the problem...

You might want to read up on: http://blog.anscamobile.com/2011/08/solutions-to-common-physics-challenges/

There's a section entitled Objects are sticking to walls.

I also had a problem with object sticking to a wall -- once it's stuck, it won't budge. If I remember correctly, I think it was because I didn't plot the physics body of the wall properly (i.e., if you are using polygon to define the physics body, it must be defined in clockwise order).

If none of the above applies to your case, hopefully, someone else will chime in to help.

Good luck.

Thanks for the support.

But no there is not physics involved in the object that is being dragged or the boundaries.

Thanks anyway, and good luck to YOU sir.

I hope someone else will help you out, Matt. I'd also like to know why this sticky dragging is happening too (for my future reference).

Then you're in luck, Naomi.
I was just having a bath and the solution came to my water wrinkled self.

1
2
3
4
5
6
7
8
9
10
11
12
13
            if (game.x > 0) then
                game.x = 0;
                return true
            elseif (game.x < -480) then
                game.x = -480;
                return true
            elseif (game.y > 0) then
                game.y = 0;
                return true
            elseif (game.y < -320) then
                game.y = -320;
                return true
            end

Cool. Glad to hear you've found the solution and hearing about it. You know, I've heard sometime ago about how our brain can come up with great solution to a problem when our mind is in idle mode. It's good to take our mind off things sometimes.

I normally come up with simple ideas that require very complex code (complex for me, maybe not so much for a pro). Usually it's when I am running, or at the beach, or at the park or hanging out with our new baby boy(6 weeks old tommorow).

The things currently on my mind

A* (the most pain in my ass algorithm)

dijkstra algorithm
^^ these 2 i'm looking at freestyle AI path finding.....yea it's a pain.

level design

etc.

I'll have to try the bathtub and write code in my head :)

ng

views:1639 update:2011/10/18 8:54:01
corona forums © 2003-2011