How i do a moving infinite background?

46 views
Skip to first unread message

Toni Roca

unread,
Jan 23, 2021, 8:36:01 AM1/23/21
to cocos2d discuss
I making a space game, and i need a infinite background loop.
And the question is , i need use a tiled map or a ScrollableLayer?

Thanks all.

claudio canepa

unread,
Jan 23, 2021, 2:26:46 PM1/23/21
to cocos2d discuss
If scrolling a single image will do, I would subclass ScrollableLayer, else it should be a subclass of a Tilemap




--
You received this message because you are subscribed to the Google Groups "cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocos-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocos-discuss/1238b3eb-f6dc-48d7-a75e-9b234415142cn%40googlegroups.com.

Ivo Fokkema

unread,
Jan 26, 2021, 3:39:24 AM1/26/21
to cocos2d discuss
I'm not sure if this is of any help, but when I had the same issue and I looked at ScrollableLayer, it seemed like I had to create a very, very large image. So I decided to use a trick instead:

background.do(Repeat(MoveBy((-500, 0), (500/SCROLLING_SPEED)) + MoveBy((500, 0), 0)))

What this does is it moves the image visibly to the left by 500 pixels in a certain amount of time (depending on the scrolling speed (set to 0-100)), and then quickly moves it back to the right by 500 pixels. This last movement isn't visible to the human eye if your image's pattern repeats every 500 pixels, but it "resets" the image position so you don't need a huge image for your level. The same image just moves left and right continuously.

I'm not saying this is better, but it is just one line of code so might help you out 😅

Cheers,

Ivo

--

Toni Roca

unread,
Jan 27, 2021, 4:53:58 AM1/27/21
to cocos2d discuss
I solved it, thanks for your responses .:)

El dia dimarts, 26 de gener de 2021 a les 9:39:24 UTC+1, Ivo Fokkema va escriure:
Reply all
Reply to author
Forward
0 new messages