<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://digida.mgpu.ru/index.php?action=history&amp;feed=atom&amp;title=Extensive_Scrolling_Engine</id>
	<title>Extensive Scrolling Engine - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://digida.mgpu.ru/index.php?action=history&amp;feed=atom&amp;title=Extensive_Scrolling_Engine"/>
	<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=Extensive_Scrolling_Engine&amp;action=history"/>
	<updated>2026-05-19T22:32:05Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=Extensive_Scrolling_Engine&amp;diff=1666&amp;oldid=prev</id>
		<title>Patarakin: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=Extensive_Scrolling_Engine&amp;diff=1666&amp;oldid=prev"/>
		<updated>2022-07-21T08:33:13Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 11:33, 21 июля 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key digida:diff:1.41:old-1665:rev-1666 --&gt;
&lt;/table&gt;</summary>
		<author><name>Patarakin</name></author>
	</entry>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=Extensive_Scrolling_Engine&amp;diff=1665&amp;oldid=prev</id>
		<title>scratch&gt;TheTrillion: Note.</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=Extensive_Scrolling_Engine&amp;diff=1665&amp;oldid=prev"/>
		<updated>2021-07-12T04:34:15Z</updated>

		<summary type="html">&lt;p&gt;Note.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[File:Extensive Scrolling World.png|thumb|240px|A project utilizing the same scrolling engine for its large open-world.]]&lt;br /&gt;
An &amp;#039;&amp;#039;&amp;#039;extensive scrolling engine&amp;#039;&amp;#039;&amp;#039; is a [[project]] engine that maintains an extensively large [[Scrolling (sprites)|scrolling]] world. Suppose a world has approximately 300 scrolling tiles for a large open-world game. Having all 300 [[Cloning|clones]] present simultaneously could cause major lag due to an excessive amount of [[script]]s and rendering. An extensive scrolling engine maintains low processing power by only generating the scrolling tiles that are nearby the current location in the project. When scrolling tiles fall too far off the [[stage]], the engine automatically deletes them. This tutorial explains how to develop and maintain a very wide-scrolling world.&lt;br /&gt;
{{note|This tutorial specifically deals only with x scrolling, but the concepts can be used for y scrolling.}}&lt;br /&gt;
{{note|This tutorial assumes the reader has basic knowledge of [[Scrolling (sprites)|scrolling]].}}&lt;br /&gt;
&lt;br /&gt;
==Preparation==&lt;br /&gt;
===Costume Arrangement===&lt;br /&gt;
Only one [[sprite]] is necessary for the entire scrolling world, because each landscape panel is a clone of the landscape sprite arranged in a row, with a different costume on.&lt;br /&gt;
&lt;br /&gt;
The first clone wears [[Costume Number (value)|costume #1]], the second clone, sitting to the right wears costume #2, and so on. The arrangement of costumes in the base sprite must match the order of the landscape move left to right, so that the &amp;lt;sb&amp;gt;(scroll x)&amp;lt;/sb&amp;gt; variable changes its value, all these clones move together.&lt;br /&gt;
&lt;br /&gt;
The variable &amp;lt;sb&amp;gt;(scroll x)&amp;lt;/sb&amp;gt; should be created to hold the [[X Position (value)|x position]] of the landscape.&lt;br /&gt;
&lt;br /&gt;
===Positioning the Landscape Panel Clones===&lt;br /&gt;
To stop the scrolling when the player moves to the far left or far right part of the game, two variables need to be created.&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
(scroll x beginning) // for this sprite only&lt;br /&gt;
(scroll x ending) // for this sprite only&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
These hold the &amp;lt;code&amp;gt;x position&amp;lt;/code&amp;gt; of the beginning and end of the landscape.&lt;br /&gt;
&lt;br /&gt;
Another variable needs to be created so that it can be used to determine if the landscape clone has left the visible area of the stage.&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
(width of view) // for this sprite only&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the initial values need to be set.&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
set [width of view v] to (600) // 600 is recommended&lt;br /&gt;
set [scroll x beginning v] to (-440) // find the value that works best for you&lt;br /&gt;
set [scroll x ending v] to (-1850) // this has 5 landscape tiles and needs to change this to fit your game.&lt;br /&gt;
set [scroll x v] to (scroll x beginning) // start from the far left&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Moving the Landscape Panel Clones===&lt;br /&gt;
When arranging landscape panel clones, the player movement input will need to be captured and used to update the &amp;lt;sb&amp;gt;(scroll x)&amp;lt;/sb&amp;gt; variable made earlier.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
forever&lt;br /&gt;
    if &amp;lt;&amp;lt;key (left arrow v) pressed?&amp;gt; and &amp;lt;(scroll x) &amp;lt; (scroll x beginning)&amp;gt;&amp;gt; then&lt;br /&gt;
        change [scroll x v] by (1)&lt;br /&gt;
	end&lt;br /&gt;
    if &amp;lt;&amp;lt;key (right arrow v) pressed?&amp;gt; and &amp;lt;(scroll x) &amp;gt; (scroll x ending)&amp;gt;&amp;gt; then&lt;br /&gt;
        change [scroll x v] by (-1)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how moving left increases &amp;lt;sb&amp;gt;(scroll x)&amp;lt;/sb&amp;gt;, this is so the landscape scrolls in the opposite direction to the player&amp;#039;s movement.&lt;br /&gt;
&lt;br /&gt;
===List Usage===&lt;br /&gt;
[[File:Clones Present List.png|thumb|101px|In the list, &amp;quot;1&amp;quot;s represent the clones currently generated within the landscape, and &amp;quot;0&amp;quot;s represent non-present clones too far off the stage.]]&lt;br /&gt;
&lt;br /&gt;
A list needs to be created to help organise the landscape panel clones.&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
(clonesPresent::list) // for this sprite only&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This list is used to control what panels are currently visible and active as opposed to the panels that are not visible and non-present.&lt;br /&gt;
&lt;br /&gt;
During every frame of the game, the landscape sprite checks the &amp;lt;sb&amp;gt;(scroll x)&amp;lt;/sb&amp;gt; variable and works out which three landscape panels need to be present. If the &amp;lt;sb&amp;gt;(scroll x)&amp;lt;/sb&amp;gt; variable&amp;#039;s value is, -480, the clones panels wear costumes 1, 2, and 3 because each costume is 480 [[pixels]] wide.&lt;br /&gt;
Once &amp;lt;sb&amp;gt;(scroll x)&amp;lt;/sb&amp;gt; reaches the value of -720, the landscape panel clones would wear costumes 2, 3, and 4. Which means the panel clone that was wearing costume on is no longer needed because its no longer visible on the stage. The landscape sprite uses the &amp;lt;sb&amp;gt;(clonesPresent)&amp;lt;/sb&amp;gt; list to work out which panel clones are &amp;#039;&amp;#039;already&amp;#039;&amp;#039; present on the stage, which is why it doesn&amp;#039;t delete the clones wearing costumes 2 and 3.&lt;br /&gt;
&lt;br /&gt;
The list should be initialized properly with the following script.&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
    delete all of [clonesPresent v]&lt;br /&gt;
    repeat (5) // &amp;quot;5&amp;quot; is the number of scrolling costumes&lt;br /&gt;
        add [0] to [clonesPresent v]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the list, every &amp;quot;0&amp;quot; represents a panel clone that is not visible on the stage, and every &amp;quot;1&amp;quot; represents every panel clone that is visible. When a panel clone is created, it sets its value in the list to &amp;quot;1&amp;quot; to show that it is a visibily present. This way the lanscape sprite only creates one planel clone for each landscape costume needed.&lt;br /&gt;
&lt;br /&gt;
When a clone moves too far off the stage, it sets its value to &amp;quot;0&amp;quot; again, because it is no longer visible.&lt;br /&gt;
&lt;br /&gt;
==Programming==&lt;br /&gt;
The following script can be used to scroll each individual panel clone until it is no longer visible on the stage.&lt;br /&gt;
&lt;br /&gt;
Once the panel clone is no longer visible, it is deleted to save memory.&lt;br /&gt;
&lt;br /&gt;
===Smooth Edge Scrolling===&lt;br /&gt;
By scaling the sprite before and after changing its position, it needs to be made so it scrolls smoothly off the Scratch stage.&lt;br /&gt;
&lt;br /&gt;
{{note|The following script assumes only horizontal scrolling is in usage.}}&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when I start as a clone&lt;br /&gt;
    set y to (0) // value can be changed to vertical position&lt;br /&gt;
    show&lt;br /&gt;
    repeat until &amp;lt;([abs v] of (((width of costume) * (costume [number v])) + (scroll x))) &amp;gt; (719)&amp;gt; // repeat until no longer visible (719 pixels)&lt;br /&gt;
        set size to (200) %&lt;br /&gt;
        set x to (((width of costume) * (costume [number v])) + (scroll x))&lt;br /&gt;
        set size to (100) %&lt;br /&gt;
    end&lt;br /&gt;
    replace item (costume [number v]) of [clonesPresent v] with [0] // records deletion of this clone&lt;br /&gt;
    delete this clone&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The panel clones&amp;#039; job is straightforward, it moves with the &amp;lt;sb&amp;gt;(scroll x)&amp;lt;/sb&amp;gt; value until too far off the stage, then it gets deleted to save memory. The landscape sprite, which creates the clone, uses the following script to check and create new panel clones with the correct costume.&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
define scroll engine // run without screen refresh&lt;br /&gt;
set [basePosition v] to (round ([abs v] of ((scroll x) / ((width of view) - (width of costume))))) // find which costume should be displayed in the middle of the screen&lt;br /&gt;
set [i v] to (-1)&lt;br /&gt;
repeat (4) // make sure the costumes surrounding basePosition are being displayed by sprites&lt;br /&gt;
	if &amp;lt;(item ((basePosition) + (i)) of [clonesPresent v]) = [0]&amp;gt; then&lt;br /&gt;
		switch costume to ((base position) + (i))&lt;br /&gt;
		replace item ((base position) + (i)) of [clonesPresent v] with [1] // clone now made&lt;br /&gt;
		create clone of [myself v]&lt;br /&gt;
	end&lt;br /&gt;
	change [i v] by (1)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, the landscape sprite needs to always run the &amp;lt;sb&amp;gt;scroll engine::custom&amp;lt;/sb&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
hide //hide the original sprite&lt;br /&gt;
forever&lt;br /&gt;
    scroll engine::custom&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
* [[Scrolling (sprites)]]&lt;br /&gt;
* [[Scrolling Platformer Tutorial]]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
* [[projects:23134940|Extensive Scrolling Example 1]], an advanced example on Scratch&lt;br /&gt;
* [[projects:368706826|Extensive Scrolling Example 2]], a simple example of this tutorial on Scratch&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Tutorials]]&lt;br /&gt;
[[Category:Game Design Tutorials]]&lt;/div&gt;</summary>
		<author><name>scratch&gt;TheTrillion</name></author>
	</entry>
</feed>