I was wrong about some things, as you can't use draw_sprite_pos for an original sprite. Since it is based around using the whole sprite, rather than part of it.
The code below does work to find out how many sprites there are in total:
Code:
begin_pos = 0;
while (sprite_exists(begin_pos))
{begin_pos += 1;}
begin_pos -= 1;
And this code below could be used, depending on how you go ahead. For example, you might create a new sprite from these dimensions and then could manipulate it with draw_sprite_pos. This should ensure you never create a sprite that is less than one pixel in width / height:
Code:
is_sprite = irandom_range(0, begin_pos);
is_width = sprite_get_width(is_sprite);
is_height = sprite_get_height(is_sprite);
start_x = irandom_range(0, is_width - 1);
start_y = irandom_range(0, is_height - 1);
end_x = irandom_range(start_x, is_width);
end_y = irandom_range(start_y, is_height);
Though creating a new sprite makes a new texture page, which is I think less efficient than using part of the sprite as a textured primitive (as flyingsaucerinvasion suggests)
If you went with a textured primitive, then it would be a bit different as the scale (what would be the sprite width / height part previously) goes from 0 to 1:
Code:
is_sprite = irandom_range(0, begin_pos);
one_pixel_width = 1 / sprite_get_width(is_sprite);
one_pixel_height = 1 / sprite_get_height(is_sprite);
start_x = random_range(0, 1 - one_pixel_width);
start_y = random_range(0, 1 - one_pixel_height);
end_x = random_range(start_x, 1);
end_y = random_range(start_y, 1);
I'm not sure about the above code, as irandom_range returns a whole number (0, or 1, in this case) - so it can't be used here, as the scale goes from 0 to 1 on a texture. random_range returns a number that isn't whole, so I think it is the one to use (0.1, 0.05, 0.72 etc) instead. If its correct then it should never draw anything less than one pixel in width / height of the sprite, and will be randomly picking what part is drawn. Then to manipulate the primitive you would use these dimensions (what part is drawn) with something like lengthdir_x / y to control the points (where its drawn)