Gap when drag scrolling background

Hmm, I don’t really understand what you’re saying. The example I posted prior to this last one had the issue with the objects all dragging with the same velocities, but correctly scrolling when touch was released. Then I went back to your latest example because it did not suffer from same issue. I was then able to incorporate some of my code into your code which took care of the drag scrolling issue I was originally having. Once I figure out the new issue, hopefully with your input, I’ll apply the logic to the longer example I posted prior.

Your latest snippet appears to only change the velocities? What am I missing?

P.S. thank so much for the link [import]uid: 12397 topic_id: 12411 reply_id: 47417[/import]

Out of curiosity, I threw the display text showing the x positions into your last example (Posted on Wed, 2011-07-20 23:18) and notice that the intermittent glitch is also present.

Any Ideas?

display.setStatusBar(display.HiddenStatusBar) -- Hide status bar  
   
   
local bg1 = display.newRect(0, 0, 1024, 768)  
local bg2 = display.newRect(-1024, 0, 1024, 768)  
bg1:setFillColor(40, 91, 142)  
bg2:setFillColor(0, 153, 102)  
  
local bg3 = display.newRect(150,100,100,100)  
local bg4 = display.newRect(370,200,100,100)  
local bg5 = display.newRect(0,100,100,100)  
local bg6 = display.newRect(924,200,100,100)  
local localGroup = display.newGroup()  
localGroup:insert(bg3)  
localGroup:insert(bg4)  
localGroup:insert(bg5)  
localGroup:insert(bg6)  
  
local function positionXDisplayUpdate()  
 bg1Text.text = "bg1.x: "..string.format("%.f",bg1.x)  
 bg2Text.text = "bg2.x: "..string.format("%.f",bg2.x)  
 localGroupText.text = "localGroup.x: "..string.format("%.f",localGroup.x)  
 bg1Text:setReferencePoint(display.CenterLeftReferencePoint)   
 bg2Text:setReferencePoint(display.CenterLeftReferencePoint)   
 localGroupText:setReferencePoint(display.CenterLeftReferencePoint)   
 bg1Text.x = 450  
 bg2Text.x = 450  
 localGroupText.x = 450  
end  
  
local function positionXDisplay()  
 bg1Text = display.newText("bg1.x: "..bg1.x, 450, 150, "Helvetica", 60)  
 bg2Text = display.newText("bg2.x: "..bg2.x, 450, 200, "Helvetica", 60)  
 localGroupText = display.newText("bg2a.x: "..localGroup.x, 450, 500, "Helvetica", 60)  
end  
positionXDisplay()  
   
   
  
--localGroup:setReferencePoint(display.CenterReferencePoint);  
-- Set up variables  
local previousX = 0  
local scrollVelocity = 0  
   
local function flickScroll() -- used to add on velocity after touch stopped  
 bg1.x = bg1.x + scrollVelocity -- make the move  
 bg2.x = bg2.x + scrollVelocity  
 if bg1.x \>= 1024 + 512 then   
 bg1.x = bg2.x - 1024  
 end  
 if bg2.x \>= 1024 + 512 then   
 bg2.x = bg1.x - 1024  
 end   
 if bg1.x \<= -512 then  
 bg1.x = bg2.x + 1024  
 end  
 if bg2.x \<= -512 then   
 bg2.x = bg1.x + 1024  
 end  
 positionXDisplayUpdate()   
 scrollVelocity = scrollVelocity \* 0.95  
 localGroup.x = localGroup.x + scrollVelocity \* 0.2  
 if localGroup.x \< - 1024 then  
 localGroup.x = 1024  
 end  
 if localGroup.x \> 1024 then  
 localGroup.x = -1024  
 end  
 if scrollVelocity \< 0.1 and scrollVelocity \> -0.1 then  
 scrollVelocity = 0  
 end  
end  
   
local flag =false  
local function makeScroll(e)  
 if "began" == e.phase then  
 x1 = e.x - bg1.x  
 x2 = e.x - bg2.x  
 x3 = e.x - localGroup.x  
 scrollVelocity = 0  
 print(localGroup.x)  
 elseif "moved" == e.phase then  
  
 scrollVelocity = e.x - previousX  
  
  
 bg1.x = e.x - x1  
 bg2.x = e.x - x2  
 print(scrollVelocity)  
 print(localGroup.x)  
 if flag then  
 localGroup.x = localGroup.x + scrollVelocity \* 0.2  
 if localGroup.x \< - 1024 then  
 localGroup.x = 1024  
 end  
 if localGroup.x \> 1024 then  
 localGroup.x = -1024  
 end  
 end  
 positionXDisplayUpdate()   
 flag = true  
 previousX = e.x  
 if bg1.x \>= 1024 + 512 then   
 bg1.x = bg2.x - 1024  
 x1 = e.x - bg1.x  
 end  
 if bg2.x \>= 1024 + 512 then   
 bg2.x = bg1.x - 1024  
 x2 = e.x - bg2.x  
 end   
 if bg1.x \<= -512 then  
 bg1.x = bg2.x + 1024  
 x1 = e.x - bg1.x   
 end  
 if bg2.x \<= -512 then   
 bg2.x = bg1.x + 1024  
 x2 = e.x - bg2.x  
 end   
 elseif "ended" == e.phase then  
 Runtime:addEventListener("enterFrame", flickScroll)  
 previousX = 0  
 flag = false  
 end  
end  
Runtime:addEventListener("touch", makeScroll)  

[import]uid: 12397 topic_id: 12411 reply_id: 47496[/import]

i had not chked that but i think so that was there because i am not removing enterFrame event

put this in “began” event ( i think that is the perfect place for it

Runtime:removeEventListener(“enterFrame”, flickScroll)
:slight_smile: [import]uid: 12482 topic_id: 12411 reply_id: 47624[/import]

That solved the glitch, thanks so much for your patience! I wish I knew why though, I figured sticking it inside the conditional at the end of flickScroll() would also work, but no. Oh well, works great… thanks again! [import]uid: 12397 topic_id: 12411 reply_id: 47634[/import]