Screen Boundaries

I have an object with physics, that can only be drag in the x direction, i am trying to set up boundaries so the object can only be dragged so far then it will stop, so it doesnt go off the screen

Thanks!!! [import]uid: 14967 topic_id: 9180 reply_id: 309180[/import]

Create 1000pixel by 1 pixel images. Then place the images slightly off screen. For example put the image like this example code.

local side2 = display.newImage(“side.png”, 500, 10);
side2:setReferencePoint(display.CenterReferencePoint);
side2.x = _W/100; side2.y = _H/2;
localGroup:insert(side2)
physics.addBody(side2, “static”, {friction = .5, bounce = .5});
I think the _W/100 could be -1 to go off screen.

I hope this helps. [import]uid: 29181 topic_id: 9180 reply_id: 33517[/import]

i have my object set to kinematic so it isnt affected by gravity, which is causing my object to go right through the side images [import]uid: 14967 topic_id: 9180 reply_id: 33521[/import]

Oh that’s a problem. Then you have to put in a collision detector. There is an example code project with corona. Check it out and rewrite it to maybe make the object stop moving…idk good luck. [import]uid: 29181 topic_id: 9180 reply_id: 33522[/import]

found a work around, thanks for the help!!! [import]uid: 14967 topic_id: 9180 reply_id: 33528[/import]

What did u do? I’m curious now. [import]uid: 29181 topic_id: 9180 reply_id: 33529[/import]

i made an image for the bottom so my object will collide with that. i then set my object right on top of the image and set object.isFixedRotation to true so it doesnt fall over, then made the side images so it wont go off the screen on the left or the right [import]uid: 14967 topic_id: 9180 reply_id: 33534[/import]

Ahhh ok. So then you turn kimatic off? [import]uid: 29181 topic_id: 9180 reply_id: 33535[/import]

ohh yes sorry, turned kinematic off and made my object dynamic [import]uid: 14967 topic_id: 9180 reply_id: 33537[/import]

Ahh very smart. What does dynamic do? [import]uid: 29181 topic_id: 9180 reply_id: 33580[/import]

objects set to dynamic are affected by gravity and collision [import]uid: 14967 topic_id: 9180 reply_id: 33599[/import]