How to detect touch on bigger area? Help me please!

I need some help here… well, i am creating a long level in my game. My level resolution is 640 x 1920 (Height x 2) and the problem is that when the camera follows the object, i can draw line only on 640 x 960 area, and my line draws on the 640 x 960 area even if i draw it somewhere at 1100 of height area… i can’t figure it out… the line and the camera are from corona docs and moveCamera is from EggBreaker example… thank you!

i added all objects to the gameGroup, yes)

In easy words: when the camera starting to follow object, my line, if i am adding it to the gameGroup, it is drawing but on ONE OF the backgrounds, i.e. 640 x 960! it is like touch area goes lower and lower… and if i am drawing on the second background, which is under the first one(for ex background1.x, y = 640, 960, background2.x, y = 640, 1200) it is drawing on the first one, which is higher!

Please, help!

[code]
W = display.contentWidth;
H = display.contentHeight;

local function createPlatform(event)
if (event.phase == “began”) then
if(line) then
line.parent:remove(line);
end
x = (event.x - (W/2 - 80));
y = (event.y - (H/2));
line = display.newLine(W/2 - 80, H/2, event.x, event.y)
line.width = 5;
physics.addBody(line, “static”, {shape = {0, 0, x, y}});
line.isBullet = true;
end
if (event.phase == “moved”) then
x = (event.x - (W/2 - 80));
y = (event.y - (H/2));
if (line) then
line.parent:remove(line);
end
line = display.newLine(W/2 - 80, H/2, event.x, event.y)
line.width = 5;
physics.addBody(line, “static”, {shape = {0, 0, x, y}});
line.isBullet = true;
end
if (event.phase == “ended”) then

end
end

Runtime:addEventListener(“touch”, createPlatform)

–Camera follows bolder automatically
local function moveCamera()
if (obj.x > 320 and obj.x < 960) then
gameGroup.x = -obj.x + 320
end
end
Runtime:addEventListener( “enterFrame”, moveCamera )[/code] [import]uid: 169507 topic_id: 32361 reply_id: 332361[/import]

Any ideas, guys? I almost lost in this thing! Can’t get it right [import]uid: 169507 topic_id: 32361 reply_id: 130968[/import]

Any ideas, guys? I almost lost in this thing! Can’t get it right [import]uid: 169507 topic_id: 32361 reply_id: 130968[/import]

somebody? :frowning: [import]uid: 169507 topic_id: 32361 reply_id: 131063[/import]

I think your problem is that touch co-ordinates are where you touch on the screen, not where you touch on your level.

So event.x and event.y can never be greater than the boundaries of the screen.

You need to adjust where you draw the line by the amount the camera group has moved. [import]uid: 93133 topic_id: 32361 reply_id: 131066[/import]

somebody? :frowning: [import]uid: 169507 topic_id: 32361 reply_id: 131063[/import]

I think your problem is that touch co-ordinates are where you touch on the screen, not where you touch on your level.

So event.x and event.y can never be greater than the boundaries of the screen.

You need to adjust where you draw the line by the amount the camera group has moved. [import]uid: 93133 topic_id: 32361 reply_id: 131066[/import]

Perhaps try adding the touch listener to the background instead of runtime and set the x/y coordinates to the background image so drawing the line on the back ground not the x/y of the screen measurements as what Nick says makes sense.

Have you used terminal? print(event.x, event.y) and print(obj.x, obj.y )within your touch code to see what co-ordinates you are drawing at compared to the object? will give you an idea of what to adjust.

Good luck [import]uid: 131622 topic_id: 32361 reply_id: 131136[/import]

Perhaps try adding the touch listener to the background instead of runtime and set the x/y coordinates to the background image so drawing the line on the back ground not the x/y of the screen measurements as what Nick says makes sense.

Have you used terminal? print(event.x, event.y) and print(obj.x, obj.y )within your touch code to see what co-ordinates you are drawing at compared to the object? will give you an idea of what to adjust.

Good luck [import]uid: 131622 topic_id: 32361 reply_id: 131136[/import]

Big thanks for advices, but no luck at all((((

i optimised a line code.

Could you help me with code, Nick? cause i honestly don’t imagine how to adjust line coordinates to gameGroup.
And should i add a line to gameGroup? thank you!

Here is an optimised code:

[code]
local line
local lineGroup = display.newGroup()
local prevX,prevY
local isDrawing = false
local i = 0

local function distanceBetween(x1, y1, x2, y2)
local dist_x = x2 - x1
local dist_y = y2 - y1
local distanceBetween = math.sqrt((dist_x*dist_x) + (dist_y*dist_y))
return distanceBetween
end

local function drawLine(e)
if(e.phase == “began”) then
if(line) then
lineGroup:remove(1)
line = nil
end
prevX = e.x
prevY = e.y
e.y = gameGroup.y
isDrawing = true
elseif(e.phase == “moved”) then
local distance = distanceBetween(prevX, prevY, e.x, e.y)
local distance_min = distanceBetween(prevX, prevY, e.x, e.y)
if(isDrawing and distance_min > 10 and distance < 150) then
local distance1 = distanceBetween(prevX, prevY, e.x, e.y)
if(line) then lineGroup:remove(1) end
line = display.newLine(prevX, prevY, e.x, e.y)
line.myName = “line”
line:setColor(255, 255, 0)
line.width = 6
local dist_x = e.x - prevX
local dist_y = e.y - prevY
line_shape = {0, 0, dist_x, dist_y, 0, 0}
physics.addBody(line, “static”, { density = 1, friction = 0.51, bounce = 1.34, shape = line_shape } )
lineGroup:insert(line)
print(e.x, e.y)
end
elseif(e.phase == “ended”) then
isDrawing = false
end
end
`` [import]uid: 169507 topic_id: 32361 reply_id: 131470[/import]

When you have an x,y location on the screen (eg: from the event parameter in a touch listener) you can convert it a display group’s relative position by calling contentToLocal() on the display group.

http://docs.coronalabs.com/api/type/DisplayObject/contentToLocal.html

If you have a display group called ‘dispGrp’ which is at {x=-100, y=100} (extends off the left of the screen but starts 100 pixels from the top) calling [lua]local x, y = dispGrp:contentToLocal( 150,150 )[/lua] would return the values: x=250, y=50

There is also ‘localToContent()’ for the reverse:

http://docs.coronalabs.com/api/type/DisplayObject/localToContent.html [import]uid: 8271 topic_id: 32361 reply_id: 131479[/import]

Big thanks for advices, but no luck at all((((

i optimised a line code.

Could you help me with code, Nick? cause i honestly don’t imagine how to adjust line coordinates to gameGroup.
And should i add a line to gameGroup? thank you!

Here is an optimised code:

[code]
local line
local lineGroup = display.newGroup()
local prevX,prevY
local isDrawing = false
local i = 0

local function distanceBetween(x1, y1, x2, y2)
local dist_x = x2 - x1
local dist_y = y2 - y1
local distanceBetween = math.sqrt((dist_x*dist_x) + (dist_y*dist_y))
return distanceBetween
end

local function drawLine(e)
if(e.phase == “began”) then
if(line) then
lineGroup:remove(1)
line = nil
end
prevX = e.x
prevY = e.y
e.y = gameGroup.y
isDrawing = true
elseif(e.phase == “moved”) then
local distance = distanceBetween(prevX, prevY, e.x, e.y)
local distance_min = distanceBetween(prevX, prevY, e.x, e.y)
if(isDrawing and distance_min > 10 and distance < 150) then
local distance1 = distanceBetween(prevX, prevY, e.x, e.y)
if(line) then lineGroup:remove(1) end
line = display.newLine(prevX, prevY, e.x, e.y)
line.myName = “line”
line:setColor(255, 255, 0)
line.width = 6
local dist_x = e.x - prevX
local dist_y = e.y - prevY
line_shape = {0, 0, dist_x, dist_y, 0, 0}
physics.addBody(line, “static”, { density = 1, friction = 0.51, bounce = 1.34, shape = line_shape } )
lineGroup:insert(line)
print(e.x, e.y)
end
elseif(e.phase == “ended”) then
isDrawing = false
end
end
`` [import]uid: 169507 topic_id: 32361 reply_id: 131470[/import]

When you have an x,y location on the screen (eg: from the event parameter in a touch listener) you can convert it a display group’s relative position by calling contentToLocal() on the display group.

http://docs.coronalabs.com/api/type/DisplayObject/contentToLocal.html

If you have a display group called ‘dispGrp’ which is at {x=-100, y=100} (extends off the left of the screen but starts 100 pixels from the top) calling [lua]local x, y = dispGrp:contentToLocal( 150,150 )[/lua] would return the values: x=250, y=50

There is also ‘localToContent()’ for the reverse:

http://docs.coronalabs.com/api/type/DisplayObject/localToContent.html [import]uid: 8271 topic_id: 32361 reply_id: 131479[/import]

Could you post the relevant portion of your code? I’m very, very certain that contentToLocal does work. You need to be aware of what object you are using it on. [import]uid: 8271 topic_id: 32361 reply_id: 139013[/import]

Can somebody help me, please?(

I think that it is just a one-line issue, i need this physics body to move.

By the way: corona with it’s “hybrid” mode shows that when i draw a line, physics body is in the right place! but actually it is not [import]uid: 169507 topic_id: 32361 reply_id: 139142[/import]

The code you’ve posted is incomplete and requires a lot of work to get it to a point where the logical problem can be resolved. Can you post the entire code please? If that requires you to post your whole game/app listing, then you need to reduce the problem to a sample file which can run on its own without other problems. [import]uid: 8271 topic_id: 32361 reply_id: 139146[/import]

could you post your e-mail? just don’t want to share this demo as it is copyright already ) [import]uid: 169507 topic_id: 32361 reply_id: 139149[/import]

I don’t mean the demo, I mean a very, very reduced set of functionality which provides only the problem you are seeing. [import]uid: 8271 topic_id: 32361 reply_id: 139151[/import]

I can’t download that file. Contact me at horace dot bury at google’s mail dot com [import]uid: 8271 topic_id: 32361 reply_id: 139155[/import]

@link@

Here is a little show up of the problem!

Really appreciate your help, man! Thank you! [import]uid: 169507 topic_id: 32361 reply_id: 139153[/import]