by DST » Sun Oct 11, 2009 6:43 pm
lol i started off using actors for points on a canvas when i first started, until i realized something....
i could do it just as easily with an array of points, like fuzz said. in fact, even easier!
So i'd have two arrays, of floats (real).
linex[20];
liney[20];
and set them at the start to whatever i wanted them to be (the heartbeat lines), then i'd have offset variables;
xoffset; and yoffset;
Then draw the lines from a loop, like this:
moveto(linex[0]+xoffset, liney[0]+yoffset); //this puts you at the start of the meter
for(i=0; i<20; i++){
lineto(linex[i]+xoffset, liney[i]+yoffset); //no moveto's needed, the turtle stays where you last drew a line to
}
and so every time the player gets hit, run another loop to change the numbers, this is even simpler:
player>collision>enemy>
float healthpercent;
health-=collide.damage; //subtract enemy damage from health
healthpercent=(health/maxhealth);
for(i=0; i<20; i++){
liney[i]*=healthpercent;
}
Of course, the linex coords don't change, unless you ...want them to! Consider that you can make the heartbeat scroll past, like a real EKG machine does, by running a loop in canvas's draw actor:
for(i=0; i<20; i++){
linex[i]-=1; if(linex[i]<=0){
linex[i]=40; } //where 40 is the width of the health meter.
}
Then, to get rid of the '1 frame behind view' glitch that the canvas has, don't use parenting, instead use direct coordinates, starting in player script.
player>draw actor>
view.x=x-vxoffset;
view.y=y-vyoffset; //where the offsets would decide what part of the screen the player is in, for instance you can set on player>createactor>
vxoffset=view.width/2;
vyoffset=view.height/2;
//and the player will stay in the center of the screen. Then do the same to sync the canvas to player's position too.
Since a program calculates all scripts, and THEN outputs the view frame, if you tell view and canvas where to be in player's draw actor, they will update properly, and nothing ever gets 'left behind one frame'.
With canvas, you've got two coords going; first the canvas draws to the spot you specify, then the parenting tells it to translate those coordinates to move with view. The dual translation results in lag even when parenting is used, its not a glitch or a problem in ge: You are actually outputting the canvas coords 1 frame too late.
But if player tells canvas to move, canvas is already in the right spot before it even begins to draw anything.
ANd then of course, using the array loop, your entire canvas draw script will be reduced to 10 lines of code, no matter how many meters you want to draw.
It also makes it easier to add lighting fx, such as two mirror loops, one above and below the current meter.
The one below is drawn with larger lines but at a transp of .75;
while the one above is drawn with smaller, brighter lines, almost white. Now you've got some lighting fx, as well as antialiasing of a sort on your canvas meter. (and you can work them all into one single loop if you like, though it would require a constant setpen command, which might slow things down more than having 3 loops.)