I can’t see it.
any help?
What probably happens here is that, by default, any object’s x and y coordinates are measured by their center. Your code is fine, but they disappear when their center reaches the edge of the screen. You need to change your anchorX value to avoid this.
You can change it like this:
nearback1.anchorX = 1 --Put it after you have defined its x and y values
Let me know how the result changes.
actually i defined my anchor point as(0,0) (default). here is my code from starting-
-- Set default anchor point for objects display.setDefault( "anchorX", 0 ) display.setDefault( "anchorY", 0 ) --------------------------------------------------------- --set background local backbackground=display.newImageRect("backback.png",2000,display.contentHeight) backbackground.x=-20+display.screenOriginX backbackground.y=-20+display.screenOriginY -------------------------------------------------------- --set nearbackground1 local nearback1=display.newImageRect("nearbk2.png",display.actualContentWidth,600) nearback1.x=0+display.screenOriginX nearback1.y=100+display.screenOriginY nearback1.anchorX=1 --set nearbackround2 local nearback3=display.newImageRect("nearbk2.png",display.actualContentWidth,600) nearback3.x=display.actualContentWidth+display.screenOriginX nearback3.y=100+display.screenOriginY nearback3.anchorX=1
and here is the result:
is there any other option?
is there any solution other than "zoomEven " scaling method
Can you use transition.to to handle the scrolling? You can still control the speed via the transition time.
Something like the following?
--set nearbackground1local nearback1=display.newImageRect("nearbk2.png",display.actualContentWidth,600) nearback1.x=0+display.screenOriginX nearback1.y=100+display.screenOriginY --set nearbackround2 local nearback3=display.newImageRect("nearbk2.png",display.actualContentWidth,600) nearback3.x=display.actualContentWidth+display.screenOriginX nearback3.y=100+display.screenOriginY local function restartscroll( self ) -- Reset the background to the right hand side self.x = w +400 -- Rerun the transition and call itself when it's done. transition.to( self, { time=5000, x=(-600), y=self.y, onComplete=restartscroll } ) end -- Scroll the object. transition.to( nearback1, { time=5000, x=(-600), y=nearback1.y, onComplete=restartscroll } ) -- transition from the right of nearback1 (the math is a guess). Don't change Y. transition.to( nearback3, { time=5000, x=(nearback1.x+300), y=nearback3.y, onComplete=restartscroll} )
thanks,i will try it
and one thing i want to ask …in function restartScroll , it seems w stands for dispaly.actualContentWidth
i tried in your way .here is my code and result
-- Set default anchor point for objects to bottom-left display.setDefault( "anchorX", 0 ) display.setDefault( "anchorY", 0 ) --------------------------------------------------------- --set nearbackground1 local nearback1=display.newImageRect("nearbk2.png",display.actualContentWidth,600) nearback1.x=0+display.screenOriginX nearback1.y=100+display.screenOriginY --set nearbackround2 local nearback3=display.newImageRect("nearbk2.png",display.actualContentWidth,600) nearback3.x=display.actualContentWidth+display.screenOriginX nearback3.y=100+display.screenOriginY local function restartscroll( self ) -- Reset the background to the right hand side self.x = display.actualContentWidth +400 -- Rerun the transition and call itself when it's done. transition.to( self, { time=5000, x=(-600), y=self.y, onComplete=restartscroll } ) end -- Scroll the object. transition.to( nearback1, { time=5000, x=(-600), y=nearback1.y, onComplete=restartscroll } ) -- transition from the right of nearback1 (the math is a guess). Don't change Y. transition.to( nearback3, { time=5000, x=(nearback1.x+300), y=nearback3.y, onComplete=restartscroll} )
result
Right, it wasn’t supposed to be an exact answer as I don’t know your background dimensions. You will need to change the X values to match what you’re using. Likely better to use variables to allow for multiple devices. (Plus your anchorX will cause a change on the XPos).
Play with the X values (-600) and see what you can do with it. As you can see, you’re getting closer (I believe).
You will need to make sure you position them next to each other for a smooth scroll. (Change the xStart of your second background)
If the effect is what you want, a little tinkering should get you what you need.
As an addendum, try removing the second sprite and get the first one working. It should start on screen and scroll to the left. (or right depending on your objective) Always better to work on one problem at a time.
You’re welcome…
In addition (better than my examples), a quick search came up with this…
https://coronalabs.com/blog/2012/10/16/parallax-simplified/
https://www.youtube.com/watch?v=zX6y7TRSIRo
https://forums.coronalabs.com/topic/65252-how-to-make-screen-scrolling-downwards/?hl=scrolling
https://forums.coronalabs.com/topic/67126-scrolling-background/?hl=scrolling
https://code.tutsplus.com/tutorials/corona-sdk-creating-a-scrolling-background–mobile-6668