Horizontal scrolling of background

0 favourites
  • 3 posts
From the Asset Store
a full game example, menu system, with the first level and a boss, to create a horizontal shooter
  • Hi.

    First, I would like to thank Kyatric for his FAQ thread and those who contributed by helping on the subject matter. The thread which I got inspiration from is titled "Scrolling Tiled Background C2" in Kyatric's FAQ(I understand I cannot put links yet since my account just got created).

    I am new to C2 - i see the community is very active and helpful. If there are any rules due to which I have to move this thread, let me know.

    I have tried to find an alternative solution for scrolling the background which I hope can be useful.

    My thought process was:

    1. Create 2 instances of the background tiled image: One which fills the layout size and the other which is placed just next to the first instance, but outside the layout;

    So:

    --one background image of size 640,480 is placed at position 0,0.

    --A second background image of same size is placed at position 640,0.

    See Kyatric's capx for resizing the image size at runtime it you prefer.

    2. I have put an even to move the background images (taken from Kyatric's capx).

    3. While the background image instances are moving, check whether the background image x position is less than the image's size.

    In my example, the name of the background image is BG. So:

    Event: BG --> X < -640

    I have put 640 being the size of the image but I think you could replace with the image's width property. Also, instead of checking the x position, maybe we could replace with checking the Is outside layout property?.

    4. If the answer to 2 above is true, create another instance of the background instance just outside the layout. The newly created instance will replace the second instance of the background image that has now scrolled to the position (0,0);

    Action: System --> Create object BG on layer 0 at (640,0)

    5. Destroy the current one which is now completely outside the layout. If it works like I am thinking it would, this may allow for better management of memory. However, this also means you cannot have the player go back, else he won't see the background.

    Action: BG --> Destroy

    If you think there is anything wrong or which can be improved, let me know. Thank you.

    I'm am sorry for not sharing my capx, but I cannot put links yet.

    Ashis

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I use exactly the same method for my ground sprite. It is possible and works good.

    If that was your question.

  • Thanks. Just wanted to add an alternative solution.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)