You must have Game-Editor 1.4.1 to use these demos, download it from here:
http://game-editor.com/forum/viewtopic.php?f=4&t=13001
ltCanvas API is dying!
Don't worry, this is a good thing. I'm going back and re-writing all the code I can think of from scratch. Introducing new features like loading in images as images or fonts, writing them easy, manipulating size and pixels, and drawing GUI using images instead! I also plan to continue to support the no-image-needed method by generating the GUI images using code instead.
ltCanvas API Changelog:
- Code: Select all
(Most Recent) 6.0 >
This update is mostly just to make all the code run
a bit smoother for the user.
Added new STYLE functionality to the drawText system
STYLE option is now a DOUBLE, 0 is still normal text,
1 is still bold text. ANY number above one will now be
the scale to draw the text at (typing "2" will draw the
text at double size). As said above, values like "1.5"
are supported, but the resulted text will be pretty weird
looking.
Added "putpixeltoscale()" function
This is the function I made to support the above scale drawing.
Functions just like putpixel() but with a third parameter to
set the scale of the pixel to be drawn. Supports DOUBLE type
scale (decimals)
Added "drawTextS()"
More or less, I've decided to ignore drawTextP. I've left the
function for the sake of backwards compatibility, but I've made
the new function drawTextS. Four parameters: text, X, Y, Style.
I've removed the RGB functions because they can be simulated with
\a000 color codes instead.
Simplified font variable list
In previous versions, every letter of the font alphabet was its
own variable. This totally clogged up the variables/menu list,
and was hard to navigate when looking at this code file. Instead,
I've replaced it with a single struct type (FONTSTRUCT) and its
resulting font data "DEFAULTFONT." These two variables should
show up in the variables/functions menu, but none of the other
letters.
Added "\v" option to drawText functions.
This new option is used to shift the text over in any direction
you want within the rows and colums of the text. Scroll down
further into the text options to see exactly how to use it. You
can even use it to type text over other text in the same command,
and make stuff like underlined text by doing something like:
drawText("Text\v-4+0____");
5.0 >
In this new version, using "CURTHEME" has been changed! It is now "THEME(CURTHEME)" to allow in-game theme switching with the function "setCURTHEME(theme_name);", so you'll have to go and edit all of your buttons for this, if you need to.
4.0 >
changed the names of some of the functions, like drawGradientPlus and drawGradientPlusPlus to drawGradientP and drawGradientF. The new textbox() functions now have one less parameter. As such, if you update an older project with this script make sure to check your code for these functions that may need to be changed!
(The image is completely on-canvas, no graphics or files!)
Now, this one's cool. Some things you can do with this code?:
- Draw coloured text anywhere on the canvas with no text actors or font files needed!
- Draw gradients between two colours anywhere on a canvas with transparency and even skew.
- Draw solid or empty rectangles easily anywhere on the canvas.
- Draw solid circles and empty ellipses / ovals anywhere on a canvas.
- Read through 2200 lines of code mostly consisting of 1's and 0's!
- Create buttons, toggle buttons, labels, counters, sliders, and even EDITABLE TEXT BOXES on canvas with only about 2 to 4 lines of code!
- Make interactive windows and menus that do fancy things!
- Be amazed!
DOCUMENTATION <- You're going to want to click that and view the documentation, as there's a TON of functions for this, it's a bit hard to figure out at first. And here's the script you need to start using them:
Load it into GameEditor by opening it up, going to Global Code (Main Menu ► Scripts ► Global Code), and doing File ► Load.
If it doesn't work the first time, try going back into global code, re-loading and re-adding it once or twice. Game-Editor is a bit tempermental with my code. Let me know if you find any glitches or errors in the code! I haven't had much time to test everything and don't know how many bugs there are. Not counting the whole skewed gradient lengthening after it gets below the skew length. That I don't feel like fixing right now.
Left-click to draw, right click to adjust size and clear the canvas.
- Code: Select all
int lockToGrid(int val, int delimiter)
{
return round(val/delimiter)*delimiter;
} // This function will return the nearest multiple of the delimiter to your value.
Usage:
- Code: Select all
Player.x = lockToGrid(Player.x, 10); //The players X value will now round to the nearest 10th pixel.
Most of the code is on the actor "Control."
(This code is OUT-OF-DATE and no longer compatible with ltCanvasTools, but the Standalone version works fine!)
Standalone
- Code: Select all
// --Drawing Functions:
// Requires setpen before use.
void drawEdges(void)
{
moveto(0, 0);
lineto(width-2, 0);
lineto(width-2, height-2);
lineto(0, height-2);
lineto(0, 0);
}
void drawGradient(char vh, int x1, int y1, int x2, int y2, double r1, double g1, double b1, double t1, double r2, double g2, double b2, double t2, double skew)
{
double xmax = max(x1, x2);
double xmin = min(x1, x2);
double ymax = max(y1, y2);
double ymin = min(y1, y2);
double i;
switch(vh)
{
default:
case 'v':
for(i=0; i<ymax-ymin; i++)
{
setpen(((1-max(i/(ymax-ymin),0))*r1)+(max(i/(ymax-ymin),0)*r2),
((1-max(i/(ymax-ymin),0))*g1)+(max(i/(ymax-ymin),0)*g2),
((1-max(i/(ymax-ymin),0))*b1)+(max(i/(ymax-ymin),0)*b2),
((1-max(i/(ymax-ymin),0))*t1)+(max(i/(ymax-ymin),0)*t2),
1);
moveto(x1,y1+i);
lineto(x2,y1+i+skew);
}
break;
case 'h':
for(i=0; i<xmax-xmin; i++)
{
setpen(((1-max(i/(xmax-xmin),0))*r1)+(max(i/(xmax-xmin),0)*r2),
((1-max(i/(xmax-xmin),0))*g1)+(max(i/(xmax-xmin),0)*g2),
((1-max(i/(xmax-xmin),0))*b1)+(max(i/(xmax-xmin),0)*b2),
((1-max(i/(xmax-xmin),0))*t1)+(max(i/(xmax-xmin),0)*t2),
1);
moveto(x1+i, y1);
lineto(x1+i+skew, y2);
}
}
}
//-- RPG bar functions! --
// Valid values for colour: 'r' (red), 'b' (blue), 'y' (yellow).
// colour is the foreground colour for the bar, the bg colour will always be red.
// The colour defaults to Green if you put in a non-valid value.
void HPDraw(double value, double max_value, char colour)
{
int ygb[3];
// Get the proper position for the health bar to
// end on the bar.
double curval = round((value/max_value) * (width-2));
switch(colour)
{
// Set the array containing our RGB value to
// a different set of colours based on the
// letter your typed in.
case 'b':
ygb[0] = 0;
ygb[1] = 0;
ygb[2] = 255;
break;
case 'g':
ygb[0] = 0;
ygb[1] = 255;
ygb[2] = 0;
break;
case 'y':
ygb[0] = 255;
ygb[1] = 255;
ygb[2] = 0;
case 'r':
ygb[0] = 255;
ygb[1] = 0;
ygb[2] = 0;
}
// Draw a background gradient from black to red.
drawGradient('h', 0,0, width,height, 255,0,0,0, 100,0,0,0, 0);
// Draw a gradient from a darker version of the selected color
// to the selected color
drawGradient('h', 1,1, curval-1, height-2, max(ygb[0]-150, 0), max(ygb[1]-150,0), max(ygb[2]-150,0), 0, ygb[0], ygb[1], ygb[2], 0, 0);
// Draw the edges of the bar
setpen(125,125,125,0,0);
drawEdges();
}
void HPDrawPlus(double value, double max_value, int r1, int g1, int b1)
{
double curval = round((value/max_value) * (width-2));
drawGradient('h', 0,0, width,height, 255,0,0,0, 100,0,0,0, 0);
// Makes sure the RGB value doesn't go below 0.
drawGradient('h', 1,1, curval-1, height-2, max(r1-150,0), max(g1-150,0), max(b1-150,0), 0, r1, g1, b1, 0, 0);
setpen(125,125,125,0,0);
drawEdges();
}
To use this function:
Create a new actor, whatever name you want, as long as it's a canvas.
Put the following code in the Draw Actor event of the canvas.
- Code: Select all
HPDraw(50, 100, 'g');
//HPDraw(current_value, max_value, colour_value);
//Valid colour values: 'g', 'b', 'y'.
//use HPDrawPlus to put in your own RGB values:
//HPDrawPlus(current_value, max_value, red, green, blue);
(These graphics are not mine, and should not be used freely in your own games. Thanks!)
Left-Click to draw selected material. Right-Click to erase.
Version 3! Added magma and cement. Magma interacts with water in interesting ways, and cement hardens when it hits certain other materials! This has also been updated with a totally new GUI showing off my GUI functionality. You can also still save and load maps. In fact, if you want to see that in action, download the example map, unzip it and place "pixmap1.map" in the same folder as "Phys.ged", and then when you run it click "Load" in the bottom right.
You can increase/decrease the amount of pixels on the map by going into Global Code, opening the "Phys" script, and changing "#define SCALE 4" to a different number. For the most amount of pixels allowed, use "#define SCALE 2", the higher the number, the less pixels on-screen.
To use this:
- Right-click the image above, click "Save As..." and save the picture.
- Go in Game-Editor and make a new actor.
- Go in that actor's control panel, and click "Text" in the top right.
- Click "New Font" and "From Image File"
- It should auto-set the number of characters to 95, if not, do it yourself.
- Click the "Initial Character" text box and type a space.
- Click OK!
Need a function to do something? Help coding? Just send me a PM and I'll see if I can help you.