Evan,
no is doesn’t work as the coordinates of the touch events are wrong. Or does an IPad has a resolution of 1536x2048?
And this is no matter if I zoom the IPad simulator in or out. Same result.
Here is the damn test code AGAIN. I am sure it is wrong and you are right.
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
-- Orientation change sample script
-- by Michael Hartlef
-- April 29th, 2010
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
display.setStatusBar( display.HiddenStatusBar )
local cw,ch = display.contentWidth, display.contentHeight
local w,h = display.stageWidth, display.stageHeight
--This variable is needed so you can modify the touch coordinates in the onTouch handler function
local orientation = 0 --portrait
-- Create the main scene group which can be rotated on an orientation change
grpScene = display.newGroup()
grpScene.xReference = cw
grpScene.yReference = ch
-- Create a text and add it to the scene group
local txt = display.newText( "Stage: "..w.." by "..h, 100, 220, "Verdana-Bold", 12 )
txt:setTextColor( 0,255,255 )
grpScene:insert(txt)
local txt2 = display.newText( "Content: "..cw.." by "..ch, 100, 240, "Verdana-Bold", 12 )
txt2:setTextColor( 0,255,255 )
grpScene:insert(txt2)
local txt3 = display.newText( "Touch: ".."000".." by ".."000", 100, 260, "Verdana-Bold", 12 )
txt3:setTextColor( 0,255,255 )
grpScene:insert(txt3)
local rect2 = display.newRect(1,1,318,478)
rect2.strokeWidth = 1
rect2:setStrokeColor( 255,255,0 )
grpScene:insert(rect2)
-- Create a circle and add it to the scene group
local circle = display.newCircle( 20, 20, 10 )
circle:setFillColor(255,0,0,255)
circle.tween = nil
grpScene:insert(circle)
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
local function onOrientationChange( event )
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
-- This code supports only 2 orientations, add the missing ones if you need them
-- or look into the manual to see how Ansca is doing it
if event.type == "portraitUpsideDown" then
transition.to( grpScene, { time=100, rotation=180 } )
orientation = 1
elseif event.type == "portrait" then
transition.to( grpScene, { time=100, rotation=0 } )
orientation = 0
end
end
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
-- Touch handler function
local onTouch = function( event )
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
-- check if the orientation is upside down and modify the touch coordinates
if orientation == 1 then
event.x = w - event.x
event.y = h - event.y
end
-- Do something when the user touches the screen
if "began" == event.phase then
txt3.text = "Touch: "..event.x.." by "..event.y
if circle.tween ~= nil then
transition.cancel(circle.tween)
end
circle.tween = transition.to(circle, {time=700, x=event.x, y=event.y})
end
end
-- Add the event listener functions for the touch and orientation change event
Runtime:addEventListener( "touch", onTouch )
Runtime:addEventListener( "orientation", onOrientationChange )
[import]uid: 5712 topic_id: 993 reply_id: 2378[/import]