Hi all,
Sorry but here is another noob question.
I am using the parallax scrolling example as a starting point. When touch is released I want to refocus back to one of my objects. I though that this would happen when touch is released s this ends the function, however it does not refocus until the touvh is reapplied and moved again.
Does anybody know why???
Here is the code I am using
function moveCamera( event )
-- when touch first begins...
if ( event.phase == "began" ) then
-- set core moveGroup to 'focused'
display.getCurrentStage():setFocus( p0, event.id )
-- set touch location to relative position (relative to moveGroup)
p0.x0 = event.x - p0.x
p0.y0 = event.y - p0.y
-- when touch moves...
elseif ( event.phase == "moved" ) then
-- set 'predicted' new X and Y positions for core moveGroup
p0.newX = event.x - p0.x0
p0.newY = event.y - p0.y0
-- in all following calculations, adjust decimals for parallax scrolling rate
-- a smaller decimal moves a layer less, so use smaller multipliers as you move back in visual space
-- in this demo, "0.4" is used for the near parallax, "0.2" used for the distant back parallax
-- if new X position is within world limits, move it there!
if ( p0.newX \<= worldLimits.XMin and p0.newX \>= adjustedXMax ) then
p0.x = p0.newX ; p1.x = p0.x\*1 ; p2.x = p0.x\*1
-- if not, lock to world limits to prevent further scrolling
elseif ( p0.newX \> worldLimits.XMin ) then
p0.x = worldLimits.XMin ; p1.x = p0.x\*1 ; p2.x = p0.x\*1
elseif ( p0.newX \< worldLimits.XMax ) then
p0.x = adjustedXMax ; p1.x = p0.x\*1 ; p2.x = p0.x\*1
end
-- if new Y position is within world limits, move it there!
if ( p0.newY \<= worldLimits.YMin and p0.newY \>= adjustedYMax ) then
p0.y = p0.newY ; p1.y = p0.y\*1 ; p2.y = p0.y\*1
-- if not, lock to world limits to prevent further scrolling
elseif ( p0.newY \> worldLimits.YMin ) then
p0.y = worldLimits.YMin ; p1.y = p0.y\*1 ; p2.y = p0.y\*1
elseif ( p0.newY \< worldLimits.YMax ) then
p0.y = adjustedYMax ; p1.y = p0.y\*1 ; p2.y = p0.y\*1
end
-- when touch ends...
elseif ( event.phase == "ended" or event.phase == "cancelled" ) then
p0.x = -bull.x + ( display.viewableContentWidth / 2 )
p0.y = -bull.y + ( display.viewableContentHeight / 2 )
end
return true
end
p0:addEventListener( "touch", moveCamera )
p0:addEventListener( "tap", worldTouchPoint )
Many Thanks
Chris [import]uid: 7388 topic_id: 3553 reply_id: 303553[/import]