Scrolling but a gap

I’m trying to scroll through two rectangles but I keep getting a gap. As far as I can tell the numbers are correct though. Is this a bug?

The device is an iPad, 1024 * 768

Thanks for any help!

~ Kai

display.setStatusBar( display.HiddenStatusBar ) basespeed = 10 local BoxOne = display.newRect(0, 192, 1024, 384) BoxOne:setFillColor(255, 0, 0, 128) BoxOne.speed = basespeed local BoxTwo = display.newRect(-1024, 192, 1024, 384) BoxTwo:setFillColor(255, 255, 0, 128) BoxTwo.speed = basespeed function Scroller(self,event) if self.x \> 1024 + 512 then self.x = -512 else self.x = self.x + self.speed end end BoxOne.enterFrame = Scroller Runtime:addEventListener( "enterFrame", BoxOne ) BoxTwo.enterFrame = Scroller Runtime:addEventListener( "enterFrame", BoxTwo )

I modified the code a bit by adding a few extra attributes to the boxes. One links the boxes together and another is to keep track of the sequence number of the box. I’m not sure why, but it’s necessary to add the speed to the first box when moving it to the end of the queue.

display.setStatusBar( display.HiddenStatusBar ) local basespeed = 10 local BoxOne = display.newRect(0, 192, 1024, 384) BoxOne:setFillColor(255, 0, 0, 128) BoxOne.speed = basespeed BoxOne.seq = 1 local BoxTwo = display.newRect(-1024, 192, 1024, 384) BoxTwo:setFillColor(255, 255, 0, 128) BoxTwo.speed = basespeed BoxTwo.seq = 2 local BoxThree = display.newRect(-2048, 192, 1024, 384) BoxThree:setFillColor(255, 255, 255, 128) BoxThree.speed = basespeed BoxThree.seq = 3 BoxOne.link = BoxThree BoxTwo.link = BoxOne BoxThree.link = BoxTwo local function Scroller(self, event) if self.x \> 1024 + 512 then self.x = self.link.x - 1024 if (self.seq == 1) then self.x = self.x + self.speed end else self.x = self.x + self.speed end end BoxOne.enterFrame = Scroller BoxTwo.enterFrame = Scroller BoxThree.enterFrame = Scroller Runtime:addEventListener( "enterFrame", BoxOne ) Runtime:addEventListener( "enterFrame", BoxTwo ) Runtime:addEventListener( "enterFrame", BoxThree )

Thanks ingemar!

I’m trying to find documentation and understand how you linked the objects – is this a standard function? Can’t find anything useful …

And yes it’s strange you have to add the extra speed for the first box.

The linking is just my own addition. No standard functions.

By adding the link attribute to each object I can easily use it in the enterFrame listener (self.x = self.link.x - 1024).

Oh … I see, I missed that detail. Nice!

I modified the code a bit by adding a few extra attributes to the boxes. One links the boxes together and another is to keep track of the sequence number of the box. I’m not sure why, but it’s necessary to add the speed to the first box when moving it to the end of the queue.

display.setStatusBar( display.HiddenStatusBar ) local basespeed = 10 local BoxOne = display.newRect(0, 192, 1024, 384) BoxOne:setFillColor(255, 0, 0, 128) BoxOne.speed = basespeed BoxOne.seq = 1 local BoxTwo = display.newRect(-1024, 192, 1024, 384) BoxTwo:setFillColor(255, 255, 0, 128) BoxTwo.speed = basespeed BoxTwo.seq = 2 local BoxThree = display.newRect(-2048, 192, 1024, 384) BoxThree:setFillColor(255, 255, 255, 128) BoxThree.speed = basespeed BoxThree.seq = 3 BoxOne.link = BoxThree BoxTwo.link = BoxOne BoxThree.link = BoxTwo local function Scroller(self, event) if self.x \> 1024 + 512 then self.x = self.link.x - 1024 if (self.seq == 1) then self.x = self.x + self.speed end else self.x = self.x + self.speed end end BoxOne.enterFrame = Scroller BoxTwo.enterFrame = Scroller BoxThree.enterFrame = Scroller Runtime:addEventListener( "enterFrame", BoxOne ) Runtime:addEventListener( "enterFrame", BoxTwo ) Runtime:addEventListener( "enterFrame", BoxThree )

Thanks ingemar!

I’m trying to find documentation and understand how you linked the objects – is this a standard function? Can’t find anything useful …

And yes it’s strange you have to add the extra speed for the first box.

The linking is just my own addition. No standard functions.

By adding the link attribute to each object I can easily use it in the enterFrame listener (self.x = self.link.x - 1024).

Oh … I see, I missed that detail. Nice!