onTouch event reversed when orientation is flipped

I need some help, I posted a few weeks ago here

http://developer.anscamobile.com/forum/2011/07/01/physics-reversed-when-orientation-flipped

I am still having trouble with it, I don’t know how to write the code so when I flip to “landscapeLeft” the object with move with my finger and not in the opposite direction

Thanks [import]uid: 14967 topic_id: 12317 reply_id: 312317[/import]

Would you be able to post the code? [import]uid: 17138 topic_id: 12317 reply_id: 44839[/import]

[code]
module(…, package.seeall)

function new()
local localGroup = display.newGroup()


local physics = require(“physics”)
physics.start()


local stage = display.getCurrentStage( )
stage:setReferencePoint(display.CenterReferencePoint)


local background = display.newImageRect( “images/bg-blur-2.png”, 1024, 768 )
background:setReferencePoint( display.CenterReferencePoint )
background.x = 512; background.y = 384
localGroup:insert( background )


local fishCollisionFilter = { categoryBits = 1, maskBits = 30 }
local fishBodyElement = { friction = .5, filter=fishCollisionFilter}


local fish = display.newImageRect( “images/fish.png”, 133, 271 )
fish:setReferencePoint( display.CenterReferencePoint )
fish.x = 512; fish.y = 630
physics.addBody( fish, “dynamic”, fishBodyElement )
fish.isFixedRotation = true
localGroup:insert( fish )


local leftCollisionFilter = { categoryBits = 8, maskBits = 1 }
local leftBodyElement = { density = 3, friction = 10, bounce = .5, filter=leftCollisionFilter}


local sideLeft = display.newRect( 0, 0, 1, 768);
sideLeft:setReferencePoint(display.CenterReferencePoint);
physics.addBody( sideLeft, “static”, leftBodyElement );
sideLeft.alpha = 0
localGroup:insert(sideLeft)


local rightCollisionFilter = { categoryBits = 16, maskBits = 1 }
local rightBodyElement = { density = 3, friction = 10, bounce = .5, filter=rightCollisionFilter}


local sideRight = display.newRect( 1023, 0, 1, 768);
sideRight:setReferencePoint(display.CenterReferencePoint);
physics.addBody( sideRight, “static”, rightBodyElement );
sideRight.alpha = 0
localGroup:insert(sideRight)


local bottomCollisionFilter = { categoryBits = 4, maskBits = 1 }
local bottomBodyElement = { friction = .5, filter=bottomCollisionFilter }


local bottom = display.newRect( 0, 767, 1024, 1 );
bottom:setReferencePoint(display.CenterReferencePoint);
physics.addBody( bottom, “static”, bottomBodyElement );
bottom.alpha = 0
localGroup:insert(bottom)


local gameText = display.newText( “Gobble Up All The Worms”, 10, 5, native.systemFontBold, 28 )
gameText:setTextColor( 0, 240, 255, 255 )
localGroup:insert(gameText)


local gulp = audio.loadSound( “sounds/gulp.caf” )

local function playGulp()
audio.play( gulp, { channel=1 } );
end


local removeBody = function( event )
local t = event.target
local phase = event.phase

if “began” == phase then
t:removeSelf()
end
return true
end


local foodCollisionFilter = { categoryBits = 2, maskBits = 1 }
local foodBodyElement = { density = 0.6, friction = 0.6, filter=foodCollisionFilter}


local foods = {}

local randomFood = function()

choiceFood = math.random( 100 )
local food

if ( choiceFood < 80 ) then
food = display.newImageRect( “images/worm.png”, 78, 62 )
food.x = 40 + math.random( 1000 ); food.y = -40
physics.addBody( food, foodBodyElement )

else
food = display.newImageRect( “images/worm.png”, 78, 62 )
food.x = 40 + math.random( 700 ); food.y = -40
physics.addBody( food, foodBodyElement )

end

foods[#foods + 1] = food
localGroup:insert(food)

food:addEventListener ( “collision”, playGulp )
food:addEventListener( “collision”, removeBody )

end

local tTimer = timer.performWithDelay( 1500, randomFood, 0 )


local function removeOffscreenItems()
for i = 1, #foods do
local oneWorm = foods[i]
if (oneWorm.x) then
if oneWorm.x < -100 or oneWorm.x > display.contentWidth + 100 or oneWorm.y < -100 or oneWorm.y > display.contentHeight + 100 then
oneWorm:removeSelf()
end
end
end
end

Runtime:addEventListener( “enterFrame”, removeOffscreenItems )


local function onTouch( event )
local t = event.target

local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true

t.x0 = event.x - t.x

elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end

return true
end

fish:addEventListener ( “touch”, onTouch )


local exitButton = display.newImageRect( “images/exitButton.png”, 64, 64 )
exitButton:setReferencePoint( display.CenterLeftReferencePoint )
exitButton.x = 955; exitButton.y = 40
exitButton.alpha = .5
localGroup:insert( exitButton )

local function pressExit (event)
if event.phase == “ended” then
director:changeScene (“cFish”, “crossfade”)
end
end

exitButton:addEventListener( “touch”, pressExit )


local function stopPhysics (event)
if event.phase == “ended” then
physics.pause()
end
end

exitButton:addEventListener( “touch”, stopPhysics )


local exitSound = media.newEventSound( “sounds/delicious.caf” )

local function playExit()
media.playEventSound( exitSound );
end

exitButton:addEventListener( “tap”, playExit )


clean1 = function ()
if gulp then
audio.stop( 1 )
audio.dispose( 1 )
gulp = nil
end
end

exitButton:addEventListener( “touch”, clean1 )


clean2 = function ()
if tTimer then
timer.cancel(tTimer)
tTimer = nil
end
end

exitButton:addEventListener( “touch”, clean2 )



return localGroup
end
[/code] [import]uid: 14967 topic_id: 12317 reply_id: 44840[/import]

I can’t see anything wrong with your code…does your build.settings file look like this?

[lua]settings =
{
orientation =
{
default = “landscapeRight”,
supported =
{
“landscapeLeft”, “landscapeRight”
},
},
} [import]uid: 17138 topic_id: 12317 reply_id: 44857[/import]

i have content = “landscapeRight” in there too, if I dont have that in there, when I turn to landscapeLeft everything is upside down. [import]uid: 14967 topic_id: 12317 reply_id: 44861[/import]

Here lets try this, build this and tell me if you have the same problem. Paste the code I gave you earlier and name it build.settings and put it in the same folder as the following code and build it to your device.

[lua]_W = display.contentWidth;
_H = display.contentHeight;

local function onTouch( event )
local t = event.target

local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true

t.x0 = event.x - t.x
elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end

return true
end

square = display.newRect(0, 0, 100, 100);
square.x = _W * 0.5;
square.y = _H * 0.5;
square:setFillColor(255,255,255);
square:addEventListener ( “touch”, onTouch ) [import]uid: 17138 topic_id: 12317 reply_id: 44868[/import]

I put in your code and it still wasnt work, then I thought maybe it had to do with the rotationfix.lua file i got from here

http://developer.anscamobile.com/code/proper-orientation-rotation-animation

so i took that out and it fixed what you have me

THANK YOU VERY MUCH FOR ALL YOUR HELP!!! [import]uid: 14967 topic_id: 12317 reply_id: 44884[/import]

No problem at all, im happy to help. Make sure you have the build.settings file because rotationfix.lua doesn’t work. [import]uid: 17138 topic_id: 12317 reply_id: 44885[/import]