P
ProjectGamesInc
Guest
Hello guys,
I'm struggling trying to create a trail on one object that is not moving.
I have this script
With that i'm good creating trails for object that are actually moving.
But for my game i have a fixed object inside a room with a moving background (so it creates the effect of a moving hero).
I can move the hero only up and down but NOT in his x axis, since all the other objects are moving towards him.
My question is, how can i draw a trail behind the hero even if its not moving? This will help a lot to create the effect of a "continuously moving hero".
Maybe there is a simplier way to code that without that script, but i can't figure it out.
Thanks.
I'm struggling trying to create a trail on one object that is not moving.
I have this script
Code:
/// @description draw_trail_scripts(length,width,color,sprite,slim,alpha)
/// @param length
/// @param width
/// @param color
/// @param sprite
/// @param slim
/// @param alpha
//Ex. draw_trail(32,32,c_white,-1,1,1)
var Length,Width,Color,Sprite,Slim,Alpha,AlphaT,Texture,Dir,Dim,Min,Height;
//Preparing variables
Length = argument0; //How many previous coordinates will use the trail
Width = argument1; //How wide will the trail be
Color = argument2; //Which color will be used to tint the trail
Sprite = argument3; //Which sprite's texture must be used for the trail. Must have "Used for 3D" marked. -1 for no sprite
Slim = argument4; //Whether the trail will slim down at the end
Alpha = argument5; //The alpha to draw the trail with (0-1), optional
ArrayTrail[0,0] = x;
ArrayTrail[0,1] = y;
Height = array_height_2d(ArrayTrail);
//Getting distance between current and past coordinates
if (Height > 1) ArrayTrail[0,2] = point_distance(ArrayTrail[0,0],ArrayTrail[0,1],ArrayTrail[1,0],ArrayTrail[1,1]) + ArrayTrail[1,2];
else ArrayTrail[0,2] = 0;
//Setting the texture
if (Sprite >= 0) {
Texture = sprite_get_texture(Sprite,0);
Dim = sprite_get_width(Sprite)/sprite_get_width(Sprite)
}
else {
Texture = -1;
Dim = 1
}
texture_set_repeat(1);
//Drawing the primitive
draw_primitive_begin_texture(pr_trianglestrip,Texture);
AlphaT = 1;
Dir = 0;
Min = min(Height - 1,Length);
for(var i = 0; i < Min; i++){
if (ArrayTrail[i,0] != ArrayTrail[i+1,0] || ArrayTrail[i,1] != ArrayTrail[i+1,1])
Dir = point_direction(ArrayTrail[i,0],ArrayTrail[i,1],ArrayTrail[i+1,0],ArrayTrail[i+1,1]);
var Len = Width / 2 - ((i + 1) / Min * Width / 2) * Slim;
var XX = lengthdir_x(Len,Dir + 90);
var YY = lengthdir_y(Len,Dir + 90);
AlphaT = (Min - i) / (Min / 2) * Alpha;
draw_vertex_texture_color(ArrayTrail[i,0] + XX,ArrayTrail[i,1] + YY,ArrayTrail[i,2] / Width/Dim,0,Color,AlphaT);
draw_vertex_texture_color(ArrayTrail[i,0] - XX,ArrayTrail[i,1] - YY,ArrayTrail[i,2] / Width/Dim,1,Color,AlphaT);
}
draw_primitive_end();
//Replacing the coordinates positions within the array
Min = min(Height,Length);
for (var i = Min; i > 0; i--){
ArrayTrail[i,0] = ArrayTrail[i - 1,0];
ArrayTrail[i,1] = ArrayTrail[i - 1,1];
ArrayTrail[i,2] = ArrayTrail[i - 1,2];
}
With that i'm good creating trails for object that are actually moving.
But for my game i have a fixed object inside a room with a moving background (so it creates the effect of a moving hero).
I can move the hero only up and down but NOT in his x axis, since all the other objects are moving towards him.
My question is, how can i draw a trail behind the hero even if its not moving? This will help a lot to create the effect of a "continuously moving hero".
Maybe there is a simplier way to code that without that script, but i can't figure it out.
Thanks.