local function screenTouch( event )

hey, 

I do not know how to create a certain touch area. 
Objective is to have a entire touch screen. If the touch is on an object then the touch event.x/ event.y will not be inside the object. It should automatically be placed next to the object. Up down Side what ever in - (~10px)  to prvent a creation event on the colliding object. 

Can someone help me with this? 

Thanks in Advance!!!

\_CX = display.contentWidth\*0.5 \_CY = display.contentHeight\*0.5 \_CW = display.contentWidth \_CH = display.contentHeight \_T = display.screenOriginY -- Top \_L = display.screenOriginX -- Left \_R = display.viewableContentWidth - \_L -- Right \_B = display.viewableContentHeight - \_T-- Bottom aspectRatio = display.pixelHeight / display.pixelWidth local toucharea = display.newRect( \_CX, \_CX, \_CW, \_CH ) toucharea.id ="toucharea" toucharea.strokeWidth = 3 toucharea:setFillColor( 0.5 ) toucharea:setStrokeColor( 1, 0, 0 ) local function screenTouch( event ) local toucharea = event.target local eventX, eventY = event.x, event.y if ( event.phase == "began" ) then display.getCurrentStage():setFocus( toucharea ) Runtime:addEventListener( "enterFrame", enterFrame ) --MOD callMenu = true elseif ( event.phase == "moved" ) then elseif ( event.phase == "ended" ) then else end return true end egg1 = display.newRect(sceneGroup, \_CX,\_CY, 50, 50 ); egg1:setFillColor( unpack(colorTable) ) egg1.xScale=0.1 egg1.yScale=0.1 egg1.id = "egg1"; schlossZetra1 = false; transMegg1 = transition.to( egg1, { xScale=1, yScale=1, time=350, tag="transMegg1", transition=easing.outElastic } ) timer.performWithDelay( 400, function() physics.addBody( egg1, "static", { bounce=0.4, friction=1.0, filter=blueCollisionFilter } ); end) egg1.gravityScale = 0; egg1.isVisible = true; #--1. Touch event is for example: eventX, eventY = \_CX, \_CY #--2. Now I want that touch event take off the (distance to the borders of the Object [width or hight] and 20 px to have always a certain distance to objetc) from the eventX, eventY = \_CX, \_CY #--3. for example the if the touch event is x/y (\_CX,\_CY) and the objetc is egg1 then the touch event should be (\_CX -/+ 65, \_CY+/-65 ) # always 15px or more distance to object

If something is unclear please feel free to Write ask … 

The whole thing is unclear really.  Touch points happen at set x,y points on the screen.  

What does “f_or example the if the touch event is x/y (_CX,_CY) and the object is egg1 then the touch event should be (_CX -/+ 65, _CY+/-65 ) # always 15px or more distance to object_”

sry for making it so unclear. 
Touch points happen at set x,y points on the screen.  
true. 

So if Touch points Start at x,y point and is in the Radius of a display.newCirlce then 
Touch points Start at x,y point should not be in the Radius of the Target object it should be outside of it … 
​I do not wankt to generate something in an object. Only beside, beyond objects not in the object. 

Is that now clear? 

​The touch event Works fine just in the case when the user is touching an object the Thrown “object” will be generated in the obstacles … I want to avoid that and put there some rules. Either it should not be possible to have a touch area there or it should move the touch points x/y ouside the obstacles. 

_## What does "for example the if the touch event is x= 50/y=60 and the object is egg1 =_display.newCirlce (50,50, 20) _then the touch event should be x= 71, y=71 #Touch Point should not Start inside the object. Should be not possible or just always outside of an __object. 

if touchpoint starts event.target then_

_ touchpoint are outside of __event.target … 

maybe with bollean? I Don t know how to Approach to this… _

now clear? I can make a Graph as well to explain if needed… 

I thought about maybe there is somehting that the touch can defekt if the touch Point Starts inside of an obstacle and then it autmatically just pushs the touch Point Start the most closest possibe beside next to the obsatcles.  _

 

You could iterate all your objects based on object.getBounds() and then decide if that object should receive a touch event.  But passing the touch event is quite complicated.

Another solution is returning the various object.getBounds() and adding an offset (so it’s bounding rect is basically larger) and using that to decide it the object was touched or not.

I struggle to grasp why you want non-touched objects to be selected unless this is some simplified kiddy game where accuracy is not a motivation.

If you simply want to find the nearest object then you need to loop outwards (in a spiral pattern) until your x,y is within an object.getBounds() and then set event.target to object and then set focus on that.

Thanks i will have an Look on that…

But passing the touch event is quite complicated.
I think i would like to learn exactly that touch event passing … 

Thanks!  If it wont work i ll update you … 

--[[IMPORTANT]]--FOCUS ON line event.xStart, event.yStart local function screenTouch( event ) local eventX, eventY = event.x, event.y if ( event.phase == "began" ) then ... elseif ( event.phase == "moved" ) then line = display.newLine( event.xStart, event.yStart, eventX, eventY ) -- line.strokeWidth = 1 ; line.alpha = 0.9 --MOD line:setStrokeColor( 0.3, 0.3, 0.3, 1 ) updatePrediction( event ) elseif (event.phase == "ended") or (event.phase == "cancelled") then ... else ... end return true end local a = switch { [1] = function (x) egg1 = display.newRect(sceneGroup,100,100, 50, 50 ); egg1:setFillColor( unpack(colorTable) ) egg1.xScale=0.1 egg1.yScale=0.1 egg1.id = "egg1"; schlossZetra1 = false; transMegg1 = transition.to( egg1, { xScale=1, yScale=1, time=350, tag="transMegg1", transition=easing.outElastic } ) timer.performWithDelay( 400, function() physics.addBody( egg1, "static", { bounce=0.4, friction=1.0, filter=blueCollisionFilter } ); end) bounds = egg1.contentBounds egg1.gravityScale = 0; -- egg1.isVisible = true; -- egg1.isHitTestable = false; -- egg1:addEventListener("touch", function() stopA=true; return true end) -- egg1:addEventListener("tap", function() stopA=true; return true end) end, default = function (x) print(x,0) print("I ll make it double and three times")end, } a:case(1) --I DO NOT KNOW HOW TO DEAL WITH -\> local bounds = egg1.contentBounds local bounds = egg1.contentBounds print( "xMin: ".. bounds.xMin ) -- xMin: 75 print( "yMin: ".. bounds.yMin ) -- yMin: 75 print( "xMax: ".. bounds.xMax ) -- xMax: 125 print( "yMax: ".. bounds.yMax ) -- yMax: 125 --I have tried to build somehting l ike this to detect if touch is in the obejct or not.. --Interval and if it is in the object the event.xStart, event.yStart should be outside of the object if event.xStart \> bounds.xMin and event.xStart \< bounds.xMax then print("X detected") if event.xStart \> egg1.x then event.xStart = bounds.xMax else event.xStart = bounds.xMin end local eventX, eventY = event.x, event.y end if event.yStart \> bounds.yMin and event.yStart \< bounds.yMax then print("Y detected") if event.yStart \> egg1.y then event.yStart = bounds.yMax else event.yStart = bounds.yMin end local eventX, eventY = event.x, event.y end &nbsp; --This Part I tried to place in local function screenTouch( event ) if ( event.phase == "began" ) then... to influence the event.xStart and event.yStart but did not work. 

hi,
unfortuntaley I stuck here again. Could not solve it.

tried to add an addEventListener to egg1 but that Kind of causes Troubles with the event.phase == “move” of the local function screenTouch( event )  …
 

Please I appreciate any help here. Please…

So you want the touch event to fire if the touch is not on green rect?

local eventX, eventY = event.x, event.y

 if ( event.phase == "began" ) then ... elseif ( event.phase == "moved" ) then line = display.newLine( event.xStart, event.yStart, eventX, eventY )

The Main Problem is the start phase and 
line = display.newLine( event.xStart, event.yStart, eventX, eventY )

I had 2 ideas regarding this: 

  1. If the touch starts in the greenbox the touch event can be cancelled. 
    I could make that with adding an event listener to the greenbox, but that caused also Problems. Because adding an event listene to greenbox caused trouble in the other touch eventlistenr “the entire screen”. When I for example started the event phase outside the Green box and during the “event phase move” I hovered the greenbox the "line = display.newLine ( event.xStart, event.yStart, eventX, eventY) " eventX, eventY stopped to update. That looked like a bug. That problem is why I cannot put an eventlister to the Green box.

Of course I add and remove everytime eventlistner during the touchpahse but that seems to be not clever and will slow down the Performance … I belive that there is a simpler solution for this… puting anything to the greenbox to make it Kind of not tocuhable  … touchenable  or simehting like this. did not work : /
 

The Option i like would Prefer… 
line = display.newLine ( event.xStart, event.yStart,
2. If the event starts in the Green box the event should instead of being cancelled the  event.xStart, event.yStart  should be placed around the greenbox. I do not know how to do it.  then there would not be a cancelled Status … event.xStart, event.yStart should work like objects which are pushen to the outside…   

I open minded for any other possible solutions here. 
To influence the “Phase began”  esspecially  the event.xStart, event.yStart  of the line … if this issues is solved I can adapt this solution to the other Parts of my game…

Thanks in Advance!   
I’ve updated the Img. Hope that is now clearer

not 
 

in phase == “began” why not simply store the event.xStart, event.yStart in 2 variables and use that?

Thanks!
Sound like a Great idea… I do not know much about store … : / Do you mean just making a local values  with the positions of rects? 
event.xStart - should include = display.contentWidth except this part [bounds.xMin - bounds.xMax] - should be not touchable or if the event should startoutside the box

event.yStart - should include = display.contentHeight except this part [bounds.yMin - bounds.yMax] - should be not touchable or if the event should startoutside the box

Can we not just make it this rect is not touchable … ? or just we have the breakground which is touchable and this area of the rect above the Background will make it not touchable … Kind of a Mask… tried that as well but did not work … 

[Forgive me: I have only skimmed this thread…]

It looks like you are mistaking the use of touch events for the action required by the touch in a particular location.

To explain…

If you want to respond to touches all over the screen but only have a (for example) line drawn if the touch begins outside of a given area, then you still need to handle a touch anywhere on the screen but begin one of two different events, depending on where the touch starts.

So, in your case (given the diagram in your last post) you would have a touch handler which takes the touch focus and simply doesn’t do anything; Eventually releasing when the  ended phase occurs.

In your second case, you would have a touch handler which takes the touch focus and starts (for example) drawing a line, until the ended phase occurs.

In the diagram above I would have had the first touch handler attached to the green rectangle and the second touch handler (as in the two sentences above) attached to the grey rectangle. Assuming the green rectangle is above the grey one, you will have an area which does not let lines get drawn, even if the touch starts inside and moves outside.

I hope that helps. (I’m pressed for time!)

something like

local eventStart = {} eventStart.x =&nbsp;event.xStart eventStart.y =&nbsp;event.yStart

you can then check if those fall into the green rect and if so you could offset them to start outside the green rect

if eventStart.x \> bounds.xMin and eventStart.x&nbsp;\< bounds.xMax and eventStart.y \> bounds.yMin and eventStart.y &nbsp;\<&nbsp;bounds.yMax&nbsp;then&nbsp; --start point is in green rect else&nbsp; --good start point end

First of all thank you very much! I’ll check if i can solve this issue…
If not I ll come back. 

Thanks. 
 

Why not just store the initial touch event:

local originalTouchEvent local function touch(e) if (e.phase == "began") then originalTouchEvent = e ...

I was keeping it simple and explaining every step   :wink:

The whole thing is unclear really.  Touch points happen at set x,y points on the screen.  

What does “f_or example the if the touch event is x/y (_CX,_CY) and the object is egg1 then the touch event should be (_CX -/+ 65, _CY+/-65 ) # always 15px or more distance to object_”

sry for making it so unclear. 
Touch points happen at set x,y points on the screen.  
true. 

So if Touch points Start at x,y point and is in the Radius of a display.newCirlce then 
Touch points Start at x,y point should not be in the Radius of the Target object it should be outside of it … 
​I do not wankt to generate something in an object. Only beside, beyond objects not in the object. 

Is that now clear? 

​The touch event Works fine just in the case when the user is touching an object the Thrown “object” will be generated in the obstacles … I want to avoid that and put there some rules. Either it should not be possible to have a touch area there or it should move the touch points x/y ouside the obstacles. 

_## What does "for example the if the touch event is x= 50/y=60 and the object is egg1 =_display.newCirlce (50,50, 20) _then the touch event should be x= 71, y=71 #Touch Point should not Start inside the object. Should be not possible or just always outside of an __object. 

if touchpoint starts event.target then_

_ touchpoint are outside of __event.target … 

maybe with bollean? I Don t know how to Approach to this… _

now clear? I can make a Graph as well to explain if needed… 

I thought about maybe there is somehting that the touch can defekt if the touch Point Starts inside of an obstacle and then it autmatically just pushs the touch Point Start the most closest possibe beside next to the obsatcles.  _

 

You could iterate all your objects based on object.getBounds() and then decide if that object should receive a touch event.  But passing the touch event is quite complicated.

Another solution is returning the various object.getBounds() and adding an offset (so it’s bounding rect is basically larger) and using that to decide it the object was touched or not.

I struggle to grasp why you want non-touched objects to be selected unless this is some simplified kiddy game where accuracy is not a motivation.

If you simply want to find the nearest object then you need to loop outwards (in a spiral pattern) until your x,y is within an object.getBounds() and then set event.target to object and then set focus on that.

Thanks i will have an Look on that…

But passing the touch event is quite complicated.
I think i would like to learn exactly that touch event passing … 

Thanks!  If it wont work i ll update you … 

--[[IMPORTANT]]--FOCUS ON line event.xStart, event.yStart local function screenTouch( event ) local eventX, eventY = event.x, event.y if ( event.phase == "began" ) then ... elseif ( event.phase == "moved" ) then line = display.newLine( event.xStart, event.yStart, eventX, eventY ) -- line.strokeWidth = 1 ; line.alpha = 0.9 --MOD line:setStrokeColor( 0.3, 0.3, 0.3, 1 ) updatePrediction( event ) elseif (event.phase == "ended") or (event.phase == "cancelled") then ... else ... end return true end local a = switch { [1] = function (x) egg1 = display.newRect(sceneGroup,100,100, 50, 50 ); egg1:setFillColor( unpack(colorTable) ) egg1.xScale=0.1 egg1.yScale=0.1 egg1.id = "egg1"; schlossZetra1 = false; transMegg1 = transition.to( egg1, { xScale=1, yScale=1, time=350, tag="transMegg1", transition=easing.outElastic } ) timer.performWithDelay( 400, function() physics.addBody( egg1, "static", { bounce=0.4, friction=1.0, filter=blueCollisionFilter } ); end) bounds = egg1.contentBounds egg1.gravityScale = 0; -- egg1.isVisible = true; -- egg1.isHitTestable = false; -- egg1:addEventListener("touch", function() stopA=true; return true end) -- egg1:addEventListener("tap", function() stopA=true; return true end) end, default = function (x) print(x,0) print("I ll make it double and three times")end, } a:case(1) --I DO NOT KNOW HOW TO DEAL WITH -\> local bounds = egg1.contentBounds local bounds = egg1.contentBounds print( "xMin: ".. bounds.xMin ) -- xMin: 75 print( "yMin: ".. bounds.yMin ) -- yMin: 75 print( "xMax: ".. bounds.xMax ) -- xMax: 125 print( "yMax: ".. bounds.yMax ) -- yMax: 125 --I have tried to build somehting l ike this to detect if touch is in the obejct or not.. --Interval and if it is in the object the event.xStart, event.yStart should be outside of the object if event.xStart \> bounds.xMin and event.xStart \< bounds.xMax then print("X detected") if event.xStart \> egg1.x then event.xStart = bounds.xMax else event.xStart = bounds.xMin end local eventX, eventY = event.x, event.y end if event.yStart \> bounds.yMin and event.yStart \< bounds.yMax then print("Y detected") if event.yStart \> egg1.y then event.yStart = bounds.yMax else event.yStart = bounds.yMin end local eventX, eventY = event.x, event.y end &nbsp; --This Part I tried to place in local function screenTouch( event ) if ( event.phase == "began" ) then... to influence the event.xStart and event.yStart but did not work. 

hi,
unfortuntaley I stuck here again. Could not solve it.

tried to add an addEventListener to egg1 but that Kind of causes Troubles with the event.phase == “move” of the local function screenTouch( event )  …
 

Please I appreciate any help here. Please…