Without the “Draw Background” block, how can I make backgrounds? What I mean is the ones starting from the left to the right, not from top to bottom. I think it would help me with making a cool game with a cool background!
It’s really simple. Here’s a quick tutorial.
Clone index explanation
This is the basic code. The first rule basically says “when I do not have enough clones to stretch halfway across the screen when they’re one pixel apart, have all of them make another one.” This means that each clone will make one, and each frame the amount of clones will double. Since this specific project only needs 512, it will create that much. It takes about a second to create them all and draw this background.
This code is in both a game starts and an object is cloned rule. This means that both the original object and all of its clones will do this code. The first block sets the initial position. As you can see, it is a set position block which uses the clone index of an object to determine its x, and puts the y to zero.
An explanation of the clone index variable
The clone index variable is a variable that is only really useful when the little bubble says self. This is because anything else would reference the original object of some object, which would definitely be equal to one. Basically, if it isn’t referencing get self, it’s going to equal one.
Clone index is a variable which has a number unique to each clone. The original object is one. The first clone made is two. The second clone made is three. The third clone made is four. The fourth clone made is five. The fifth clone made is six. Etc.
This means that we can position each clone exactly 2 pixels (or not really, but that doesn’t really matter) apart by multiplying this number by two. However, you do not forget to subtract one from the clone index, the first two pixels will not be drawn on. This is because clone indices start at one, not zero. One times two is two, not zero.
The draw a trail block is the color that will be at the top of the screen. Inside of it, the first set position [set position to x: (self x position) y: (height)] basically means
Set y to top of the screen. This draws a single trail from the bottom to the top in the color you added to the draw a trail block.
The second block, set trail color, changes the trail color to the one you want on the bottom. The third block (
set position x: (self) x position + 1, y: 0) sets the position to the clone’s x position plus one, which is almost the same as change x by one. It also goes from the top of the screen to the bottom of the screen. Because both the x and y are different before the block than they are after the block, this draws a diagonal line. In the first block, only the y is different, which means that it draws a vertical line.
That’s all the code you need. This same code adapts to any size screen, so you can do the exact same code no matter what. I did mine on a 1024x768 screen, but you can do it on whichever screen size you want. Maybe not a 1x1 I guess.
Here is the result.
Let me know if there is anything that confused you or you want to know more about and I will explain it to you.
I tried programming a rotate tool for my infinite building blocks but I couldn’t figure it out
@Petrichor Great explanation!
@MewtwoCreator You can also create backgrounds using large emojis as explained in this topic: