Bubble Ball adult touch issue

First off: Big congratulations to Robert Nay!

Interview: http://www.indiegamepod.com/podcasts/naygames-podcast-final.mp3

Now the tech; As touched on in the interview the drag operation for small pieces in Bubble Ball can be a bit tricky if you have fat fingers. I just wanted to mention (just in case no-one had yet) that if you add the graphic to a display group and, lets say, a rectangle which is slightly larger to the same display group, then set the alpha of the rectangle to 0 and isHitTestable to true (deep breath) and then attach the touch listener to the (now invisible) rectangle then the piece will be more easily dragged. The listener function should be on the display group containing the piece and the rectangle, but the listener object should be the rectangle.

Right, that’s enough rambling. Just thought I should mention it as Robert said in the interview that people had commented on it.

Good luck with your dev and we’re all looking forward to your next game!

m [import]uid: 8271 topic_id: 5148 reply_id: 305148[/import]

Hi horacebury
This is exactly what I need but with a gear.
Can you give me a little help ? [import]uid: 13156 topic_id: 5148 reply_id: 19112[/import]

Code!

What’s the situation? Really small gears? Do you have code sample you can post?

m [import]uid: 8271 topic_id: 5148 reply_id: 19120[/import]

Hi
Thanks for an answer …

My thread
http://developer.anscamobile.com/forum/2011/01/26/touch-and-rotation

The problem is when I touch the object the gear shows up and i can rotate it, but when I touch another object and rotating it exactly the same why touching the gear both object are rotating :frowning:

[code]
local dragItem = function(event)

local t = event.target
local phase = event.phase

if “began” == phase and ball.isActive == false then

display.getCurrentStage():setFocus( t )
t.isFocus = true
t.x0 = event.x - t.x
t.y0 = event.y - t.y
event.target.bodyType = “kinetic”
gear.isVisible = true
gear.alpha = 0.3
gear.x = event.target.x
gear.y = event.target.y
event.target:toFront()

elseif t.isFocus then
if “moved” == phase and ball.isActive == false then
t.x = event.x - t.x0
t.y = event.y - t.y0
gear.x = event.target.x
gear.y = event.target.y

elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil)
t.isFocus = false

if (not event.target.isPlatform ) then
t.isFocus = false

local rotate = function(event)
local xOffset = gear.x
local yOffset = gear.y
local angleBetween = mCeil(mAtan2( (event.y - yOffset), (event.x - xOffset) ) * 180 / mPi) + 90
gear.rotation = angleBetween + 180

t.rotation = gear.rotation — this is a problem !!!

end

event.target.bodyType = “static”
physics.addBody(t, “static” ,{density = 2.0, friction = 1.3, bounce = 0.2} )
gear:addEventListener(“touch”, rotate)

end
end
end
return true

end
[/code] [import]uid: 13156 topic_id: 5148 reply_id: 19122[/import]

When I justify the code in your snippet, it looks like the return true and the last end are outside of the function defined in the first line. Is that right?

m [import]uid: 8271 topic_id: 5148 reply_id: 19198[/import]

No , it’s ok I check it twice.
I think maybe I should use event.target.id because right know t (event.target) is the same for both object.
I don’t understand this I thought that when I touch another object the event.target is change.
Why two object are rotating ? [import]uid: 13156 topic_id: 5148 reply_id: 19201[/import]

Answer posted to: http://developer.anscamobile.com/forum/2011/01/26/touch-and-rotation#comment-19206

Will continue discussion there as this would become off-topic.

m [import]uid: 8271 topic_id: 5148 reply_id: 19207[/import]

@horacebury

Hi. Used your method at the top to create a larger area around a small object for dragging, and it worked great! Question. The smaller object inside the rect is supposed to be kinematic so that I can drag it and then have balls bounce off it. I have two boards that I want to drag independently of each other. After I group, the balls fall right through the board. When I use setDrawMode, it shows a wireframe around the board. Do I need something different for the physics?

local rectBoard1 = display.newRect ( 125, 78, 60, 50 )  
rectBoard1.isVisible = true  
rectBoard1.isHitTestable = true  
  
local board1 = display.newImage( "board01.png", 150, 50 )  
board1.rotation = -85  
physics.addBody( board1, "kinematic", { bounce = 0, filter = platformCF } )  
boardReset1 = board1  
  
local boardGrp1 = display.newGroup( )  
boardGrp1:insert( rectBoard1 )  
boardGrp1:insert( board1 )  
  
local rectBoard2 = display.newRect ( 125, 150, 60, 50 )  
rectBoard2.isVisible = false  
rectBoard2.isHitTestable = true  
  
local board2 = display.newImage( "board01.png", 150, 150 )  
board2.rotation = -85  
physics.addBody( board2, "kinematic", { bounce = 0, filter = platformCF } )  
boardReset2 = board2  
  
local boardGrp2 = display.newGroup( )  
boardGrp2:insert( rectBoard2 )  
boardGrp2:insert( board2 )  
  
.  
.  
.  
  
boardGrp1:addEventListener( "touch", startDrag )  
boardGrp2:addEventListener( "touch", startDrag )  

[import]uid: 25480 topic_id: 5148 reply_id: 21341[/import]

I’m not sure, but are you sure you’re not falling foul of this issue:

http://developer.anscamobile.com/forum/2011/02/04/how-detect-collision-between-static-and-kinematic-objects

Perhaps you need to be flipping the body type during the drag?

matt [import]uid: 8271 topic_id: 5148 reply_id: 21396[/import]

Thanks, Matt.

I did further testing. If the board’s original location is in the path of the balls, the physics/collision works and the balls bounce off it. However, when I drag the board the balls continue to bounce off where the board was originally located and fall right through the board at its new dragged location.

I have seen this problem somewhere in the forum … now if I can only find it again. [import]uid: 25480 topic_id: 5148 reply_id: 21413[/import]

Found it: http://developer.anscamobile.com/forum/2011/01/23/help-moving-display-group-odd-results-game-thinks-objects-are-still-original

It says to put all collision objects in the same group. Right now it’s not letting me insert the balls into the group (keeps telling me: table expected). Still trying… [import]uid: 25480 topic_id: 5148 reply_id: 21421[/import]

Okay, figured out how to get the balls into the group along with the board/rect. I drag the board/rect where I want it. Then I push the button that drops the balls … and the balls’ starting location has moved over the x,y amount that I dragged the board/rect … which makes sense because they’re all in the same group now.

Thought about using a weld joint … but you can’t use that with kinematic bodies.

I’m at a loss, again, as to how to increase the “touch” area for a drag-able object. [import]uid: 25480 topic_id: 5148 reply_id: 21496[/import]

Whew. Finally figured it out. You don’t need to put anything in a group (though I assume at some point as I mess with levels and all that jazz that I’ll have to figure out how to use groups to my advantage). But the answer ended up being pretty easy. I used the dragBody example from … um … DebugDraw? Is that the one? I think it is. Anyway I only had to add a few lines:

[code]
local function startDrag( event )

local t = event.target

if t == rectBoard1 then --rectBoard1 and rectBoard2 are my large invisible rectangles
z = 1 --the board(platforms) that they move when they’re dragged
else --are in a table so I need this to determine the index
z = 2
end

local phase = event.phase
if “began” == phase then

display.getCurrentStage():setFocus( t )
t.isFocus = true

– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y

boardM[z].x0 = event.x -boardM[z].x --just move the x,y coords along with the drag target
boardM[z].y0 = event.y -boardM[z].y --it’s that easy. The boards have bodyType kinematic

elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0

boardM[z].x = event.x -boardM[z].x0
boardM[z].y = event.y -boardM[z].y0

elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false

end

end

return true – Stop further propagation of touch event

end – ends the platform dragging
[/code] [import]uid: 25480 topic_id: 5148 reply_id: 21638[/import]