yes, I made a topic about a somewhat string method before but I’ve improved it greatly so here’s a tutorial on it
Some notes
- I strongly suggest doing this in 1 object unless you want to break the project
- in theory the filesize of the finished product should be a lot smaller then if you were to use a non string method
- even though it may be harder to spot mistakes, I believe this is a lot easier of a method
- if you want to do this with over 100 colors and are confused, @ me and I will explain what you need to change
Setup
this is pretty easy to setup, so let’s dive right in
first, you want to get the clones setup
the code for this is
when game starts {
set PixelSize to __ // Size of 1 pixel
set self TotalClones to PixelSize * ___ // ___ is the number of lines
ability Clone {
if self(total clones) < originalObject(total clones) {
create a clone of this object
}
// do this in a when object is cloned rule too
basically this initializes all the clones so they are ready to draw
then, in the when object cloned rule you want to set the position
it would look like this:
when object is cloned {
ability Clone
set position x ___ y ___ – self clone index // __ are for whatever values you want
}
now that that is set up, it’s on to the
Colors
this is probably the most tedious part, but it isn’t too hard. the basic code to set this up is:
when characters in self(PixelString) between 0 and 2 [3 for 100+ colors] matches 01 {
set self(Color) to "R100G100B100"
}
this sets a color to a string that will be interpreted in the interpreter
basically if the first 2 [or 3] characters of self(PixelString) are equal to 01 then it knows you want the first color and sets the color string to a color
you would do this for every color. sounds boring, I know, but it will pay off and setting up the colors are usually tedious
you will notice that if you add a lot of colors + clones it will start to lag. this is why it must be done in 1 object, else there will be a lot more lag (if I am correct)
I’ve tested this with 130 colors and 500 clones and the FPS drops to about 30, so it isn’t horrible. I haven’t tested it with 500 clones all doing 500 pixels though
The interpreter
setting up the interpreter is by far the hardest part, it may look complex but if you think about it it makes sense
the code for the interpreter is:
ability Interpreter {
repeat times length(self(PixelString)) / 6 [7 for 100+ colors] {
set self(ConsecutivePixels) to characters in self(PixelString) between 3 and 5 [4 and 6 for 100+ colors]
// fetches the consecutive pixels
draw trail color(R (characters in self(Color) between 1 and 4) G (characters in self(Color) between 5 and 8) B (characters in self(Color) between 9 and 12)) width 1 {
set position x self(x position) + (game(PixelSize) * self(ConsecutivePixels) y self(y position)
// moves forward
}
set self(PixelString) to characters in self(PixelString) between 7 [8 for 100+ colors] and length(self(PixelString)) + 1
// pushes read pixel out of the string so it is not repeated
}
}
I don’t understand any of this!
don’t worry, once I show you how to draw the pixels it will make more sense. basically this just gets all the data and interprets it so it outputs pixels
Drawing the pixels
you’ve finally reached the fun point—this is probably the easiest part.
the code to draw a pixel is:
set self(PixelString) to
"01*01;
02*02;"
what is this alien language?
let me explain. this first number is the color represented by a number, so if you did it based on a sandbox pixel art it would correspond with the number you see
the asterisk is saying how many times the pixel is to repeat
and the set of 2 numbers after that is how many times the pixel repeats. take the first line; the pixel would repeat only once. in the second line the pixel draws twice
as I’ve done before, I made the semicolon a breakup character as well as a new line for each pixel “chunk”
Adding a new line
you will be using the same object for every line, so this could get complicated if you do it inefficiently
the basic code for adding a new line is:
when object is cloned {
check once if self(clone index) < game(PixelSize) + 1 and self(clone index) > 0 {
set self(PixelString) to ____ // a pixel string
}
// this is for line 1
}
you would make a new rule for each new line. I’m not sure how efficient this would be if doing 500 lines, but you should do the calculations instead of using math as math tacks on more file size than a normal number
I think that covers it, as always let me know if I messed up or you need help
- Makes sense, good tutorial
- I am confused
0 voters
@/The_Somebodies @/omtl
sorry for 2 tags in 2 days