Rotation Problem

Hi dear
i build one puzzle it is working nice and i wrote rotationfix …but when device(i-pad) rotated then puzzle is not working properly like:(puzzle pieces not selecting, puzzle piece not appears …etc)

i am sharing code please help me::
[lua]if i <= max1 then
xRef = -125 + 250 * ( i - 1 )
yRef = -125
elseif i > max1 and i <= max2 then
xRef = -125 + 250 * ( ( i - max1 ) - 1 )
yRef = 125
end

pzObject[i].xReference = xRef
pzObject[i].yReference = yRef

if shadowOn then
pzShadow[i].xReference = xRef
pzShadow[i].yReference = yRef
end

pzObject[i].top = pzObject[i].y - 100
pzObject[i].bottom = pzObject[i].y + 100
pzObject[i].left = pzObject[i].x - 100
pzObject[i].right = pzObject[i].x + 100
end
local checkLocation = function( index )
local i = index

pzObject[i].xReference = 0
pzObject[i].yReference = 0

local xCenter = 727
local yCenter = 372

local left = xCenter - placementBuffer
local right = xCenter + placementBuffer
local top = yCenter - placementBuffer
local bottom = yCenter + placementBuffer

if pzObject[i].x > left and pzObject[i].x < right and pzObject[i].y > top and pzObject[i].y < bottom and pzObject[i] == finalPiece then

audio.play(tap)

print( “Puzzle piece placed!” )

check=false
finalShadow.isVisible = false
placedCount = placedCount + 1

if placedCount == maxPieces then
–THE PUZZLE IS FINISHED! DO COOL EFFECT
print(“Good Job”)
– bg=display.newRect(0,0,1024,768)
– bg:setFillColor(0,0,0,125)
– bg.isVisible = true

–local winner = display.newImage(“blackpuz.png”)
– winner.x = 727
– winner.y = 372

local winner2 = display.newImage (“conga.png”)
winner2.alpha = 0
winner2.x =230
winner2.y =422
transition.to(winner2,{time = 1000 , alpha = 1, x =230 , y =422 , transition = easing.outQuad})

local applause = audio.loadSound(“claps.mp3”)
audio.play(applause)

local winner3 = display.newImage (“stars.png”)
winner3.x = 230
winner3.y = 315
winner3.alpha = 0
transition.to(winner3,{delay = 1000 , time = 1000 , alpha = 1, x =230 , y =315 , transition = easing.outQuad})

previewBtn.isVisible = false
shufflebtn.isActive = true

local i = 1
local function nextPiece()
i = i + 1
if i <= maxPieces then
transition.to( pzObject[i], { time=50, alpha=1.0, onComplete=nextPiece } )
end
end
transition.to( pzObject[i], { time=50, alpha=1.0, onComplete=nextPiece } )
end
pzObject[i].canMove = false
pzObject[i].x = xCenter
pzObject[i].y = yCenter

resetReference( i )
return true
else
resetReference( i )
return false
end
end

local createPuzzle = function()
local i
local puzzleFile = “puzzle” … puzzleNum … “.png”

puzzlePreview = display.newImageRect( puzzleFile, 500, 500 )
puzzlePreview.x = 727
puzzlePreview.y = 372
puzzlePreview.alpha = 0

puzzlePreview.isVisible = false

for i=1,maxPieces,1 do
pzObject[i] = display.newImage( puzzleFile, 500, 500 )
if shadowOn then
pzShadow[i] = display.newImageRect( “shadow.png”, 500, 500 )
localGroup:insert( pzShadow[i] )
end
localGroup:insert( pzObject[i] )
pzObject[i].x = 727
pzObject[i].y = 372

if shadowOn then
pzShadow[i].x = 727
pzShadow[i].y = 372
pzShadow[i].alpha = 0.5
pzShadow[i].isVisible = false
end

local maskFile = “mask2-0” … i … “.png”
pzMask[i] = graphics.newMask( maskFile )
pzObject[i]:setMask( pzMask[i] )

if shadowOn then
pzShadow[i]:setMask( pzMask[i] )
end
pzObject[i].canMove = true
resetReference( i )

local touchPz = function( event )
if not isSelected and event.phase == “began” and event.x > pzObject[i].left and event.x < pzObject[i].right and event.y > pzObject[i].top and event.y < pzObject[i].bottom and pzObject[i].canMove then
isSelected = true
lastPiece = pzObject[i]
if shadowOn then
lastShadow = pzShadow[i]
end
isDragging = true
elseif event.phase == “ended” then
lastPiece = nil
if shadowOn then
lastShadow = nil
end
checkLocation( i )
end
end
pzObject[i]:addEventListener( “touch”, touchPz )
end
end

local startDrag = function( event )
if isReady then
if event.phase == “began” then
finalPiece = lastPiece

check=true

if shadowOn then
finalShadow = lastShadow
end
if finalPiece then

if shadowOn then
finalShadow.isVisible = true
finalShadow:toFront()

end

finalPiece:toFront()

transition.to(finalPiece , { time =500 , xScale = 1.0 , yScale = 1.0 } )

if shadowOn then
transition.to( finalShadow , { time =500 , xScale = 1.0 , yScale = 1.0 } )
end
end

elseif event.phase == “ended” then
isDragging = false
isSelected = false

if finalPiece and check then
transition.to( finalPiece , { time =500 , xScale = 1 , yScale = 1 } )
else
transition.to( finalPiece , { time =500 , xScale = 1 , yScale = 1 } )
end
if finalShadow and check then
finalShadow.isVisible = false
transition.to( finalShadow , { time =500 , xScale = 1 , yScale = 1 } )
else
transition.to( finalShadow , { time =500 , xScale = 1 , yScale = 1 } )
end
end

if isDragging and finalPiece then
finalPiece.x = event.x
finalPiece.y = event.y
if shadowOn then
finalShadow.x = event.x
finalShadow.y = event.y
end
end
end
end

local scatterPuzzle = function()
audio.play(scat)
local i = 1

local randX = mRand( 100, 300 )
local randY = mRand( 200, 600 )

local function nextPiece()
i = i + 1

if i <= maxPieces then
local randX = mRand( 100, 300 )
local randY = mRand( 200, 600 )

transition.to( pzObject[i], { time=50, x=randX, y=randY, rotation=endRot, onComplete=nextPiece } )

if shadowOn then
transition.to( pzShadow[i], { time=50, x=randX, y=randY, rotation=endRot, onComplete=nextPiece } )
end
else
– activate buttons
– newPuzzleBtn.isActive = true
previewBtn.isActive = true
– solveItBtn.isActive = true

– ready for dragging pieces around
isReady = true
Runtime:addEventListener( “touch”, startDrag )
end
end

transition.to( pzObject[i], { time=50, x=randX, y=randY, rotation=endRot, onComplete=nextPiece } )

if shadowOn then
transition.to( pzShadow[i], { time=50, x=randX, y=randY, rotation=endRot, onComplete=nextPiece } )
end
end
local drawBackground =function()
local bgImage = display.newImageRect( “background2.png”, 1024, 768 )
bgImage.x = 512
bgImage.y = 384
localGroup:insert( bgImage )

dimRect = display.newRect( localGroup, 0, 0, 1024, 768 )
dimRect:setFillColor( 0, 0, 0, 255 )
dimRect.alpha = 0
dimRect.isVisible = false
end

local touchPreviewBtn = function( event )
if event.phase == “ended” and previewBtn.isActive then
audio.play(tapSound)
previewBtn.isActive = false
Runtime:removeEventListener( “touch”, startDrag )
local startTouchEvent = function()
local function closePreview( event )
if event.phase == “ended” and not previewBtn.isActive then
audio.play(tapSound)
previewBtn.isActive = true
dimRect.alpha = 0
dimRect.isVisible = false
transition.to(puzzlePreview, {time=1000,alpha=.30})
transition.to(puzzlePreview, {delay=1500,alpha=0})

Runtime:removeEventListener( “touch”, closePreview )
Runtime:addEventListener( “touch”, startDrag )
end
end
Runtime:addEventListener( “touch”, closePreview )
puzzlePreview.isVisible = true
transition.to( puzzlePreview, { time=200, alpha=1.0 } )
end
dimRect:toFront()
puzzlePreview:toFront()
dimRect.isVisible = true
transition.to( dimRect, { time=500, alpha=0.75, onComplete=startTouchEvent } )
end
end

local tomenu =function (event)
if event.phase == “ended” then
audio.stop( scat )
audio.stop( tap )
audio.play(tapSound)
director:changeScene (“menu”)
end
end

local fshuffle = function(event)
if event.phase == “ended” then
audio.stop( scat )
audio.stop( tap )
audio.play(tapSound)
director:changeScene (“Puzzle2”)
end
end

local puzz2 =function (event)
if event.phase == “ended” then
audio.stop( scat )
audio.stop( tap )
audio.play(tapSound)
director:changeScene (“Puzzle2”)
end
end

local puzz4 =function (event)
if event.phase == “ended” then
audio.stop( scat )
audio.stop( tap )
audio.play(tapSound)
director:changeScene (“Puzzle4”)
end
end

local createMenu = function()
previewBtn =display.newImage(“previewbtn.png”)
previewBtn.x = display.viewableContentWidth/2
previewBtn.y = display.viewableContentHeight/1.1
localGroup:insert( previewBtn )
previewBtn:addEventListener(“touch”,touchPreviewBtn)

shufflebtn =display.newImage(“shuffle.png”)
shufflebtn.x = display.viewableContentWidth/1.08
shufflebtn.y = display.viewableContentHeight/1.1
localGroup:insert( shufflebtn )
shufflebtn:addEventListener(“touch”,fshuffle)

local menubtn = display.newImage(“menu2.png”)
menubtn.x = display.viewableContentWidth/15
menubtn.y = display.viewableContentHeight/1.1
localGroup:insert( menubtn )
menubtn:addEventListener(“touch”,tomenu)

local puz2 = display.newImage (“twor.png”)
puz2.x = display.viewableContentWidth/1.55
puz2.y = display.viewableContentHeight/1.1
localGroup:insert(puz2)
puz2:addEventListener(“touch”,puzz2)

local puz4 = display.newImage (“four.png”)
puz4.x =display.viewableContentWidth/1.3
puz4.y= display.viewableContentHeight/1.1
localGroup:insert(puz4)
puz4:addEventListener(“touch”,puzz4)
end

local appInit = function()
drawBackground()
createPuzzle()
createMenu()
timer.performWithDelay( 1000, scatterPuzzle, 1 )
Runtime:addEventListener( “touch”, startDrag )
dimRect:toFront()
puzzlePreview:toFront()
end
appInit()[/lua]

[import]uid: 87661 topic_id: 18637 reply_id: 318637[/import]

Since you have a lot of code there. Could you make the code more plug and play friendly?

Meaning can you replace all of the image objects with display.newRect() and remove all of the sound references and also remove any other resources that I probably do not have access to. [import]uid: 94868 topic_id: 18637 reply_id: 71607[/import]