How To Make A Space Shooter Game (Infinte Scrolling Background) Construct 2
To dynamically ringlet through a very big background made up of smaller frames, there are many different solution; the principal idea though is quite the same.
The main idea
Think of your fifteen groundwork frames as sort of "panels", which you draw one along the other and so that they fit the current view
width: if your view is 1280 pixels wide, and each groundwork is 960 pixels broad, then you need at least three backgrounds per time to fit the electric current view
; this looks obvious if one of the "panels" fits within the current view:
Cycling through panels
With this setup, nosotros expect background 1 in the image to disappear equally soon as it lies completely out of our view
borders; later, when background 3 find itself completely inside the view
borders, nosotros need to depict the new background four following the number iii seamlessly.
Make it simpler
Nosotros can tear down the global complexity of our solution past making some considerations:
- We can use a stock-still number of scrolling panels (backgrounds) as long as they fit the
view
range, as showed ealier, in number equal to or greater that the minimum required; - In GM:S, since we have a limited number of available backgrounds, instead of loosing past backgrounds and allocating new ones (not possible because background indices are stock-still in GM:S), we can just shift the
background_index
es in a proper manner to make the whole bigger background be fatigued seamlessly.
All this realizes as follow. First, we draw the first due north backgrounds; when the n-th groundwork lies within the view
borders, thus we now need to draw the n+1-thursday background, nosotros shift the north backgrounds back (for example, along the positive direction of 10 axis) of value northward*background_width; finally, we make the n-th groundwork equal to the first - so that information technology will really be drawn in the same previous position regarding the room view
- and so assign the new backgrounds to the indices to follow.
If we brand n = 5, we achieve the post-obit:
- Starting cycle: backgrounds i to five;
- First iteration: backgrounds 5 to ix;
- 2nd iteration: backgrounds 9 to xiii;
- Boss iterations: backgrounds 13, fourteen, 15, 12, 13
The "dominate iteration" will occur through the same backgrounds continuously and seamlessly, thanks to a useful choice of numbers.
Implementation
Have one object to control straight the groundwork movement.
In its Create Effect, you assign the backgrounds and their offsets:
// Assign background indices background_index[0] = bgFrame0; background_index[1] = bgFrame1; background_index[2] = bgFrame2; background_index[3] = bgFrame3; background_index[4] = bgFrame4; // Shift backgrounds (otherwise they volition be overlapped) for (var i=ane; i<5; i++) // bkgr0 starts at (0,0) background_x[i] += i*bk_width; // bk_width is the width of single backgrounds
Then, in the Step Event (or like):
// Update backgrounds' relative positions for (var i=0; i<5; i++) background_x[i] -= 5; // an alternative to background_hspeed[] // Alter the backgrounds stack when needed if (background_x[iv]<=0) // if the terminal background lies within the view { for (var i=0; i<five; i++) // push back all five backgrounds background_x[i] += bk_width; // (maintaining their relative offsets) background_index[0] = background_index[four]; // terminal console becomes the first one // change other backgrounds here }
Final touch
Where I commented // change other backgrounds here
, you can implement a switch
statement that changes background_index[one]
to background_index[4]
upon looking up a counter variable telling you which groundwork cycle to draw (starting, showtime, 2d, or boss).
Important affair is, before changing these background_index
es, you lot must always execute background_index[0] = background_index[4]
to make the transition seamless.
How To Make A Space Shooter Game (Infinte Scrolling Background) Construct 2,
Source: https://gamedev.stackexchange.com/questions/140154/programmatically-creating-a-continuous-scrolling-background-in-game-maker-studi
Posted by: marchfaryinly.blogspot.com
0 Response to "How To Make A Space Shooter Game (Infinte Scrolling Background) Construct 2"
Post a Comment