• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

blood splatter effect

S

stepup2000

Guest
so im making a top down shooter and i wanted to make a blood splatter effect for when you kill an enemy, i did this by making a controller object for the blood. Then when the enemy gets destroyed he makes 25 blood object that each go in a random 360 degree and random speed. Then when the blood object stops i let it transfer his coords to the blood controller to an array, the blood controller then draws blood sprites at the right coords. I do it this way so i can have a lot of blood sprites but it wont hurt the fps that much. But i got an error i dont understand, the error is this:

action number 1
of Draw Event
for object obj_blood_decals:
trying to index a variable which is not an array
at gml_Object_obj_blood_decals_Draw_0 (line 7) - draw_sprite(spr_blood, 0, Blood[0], Blood[1]);


the codes i used are:

obj_blood decals //blood controller

//create
Splatter = ds_list_create(); // Prepare an empty list.
Splatter_Count = 100; // Maximum allowed number of items on the list.

//clean up
ds_list_destroy(Splatter);


//end step
if(ds_list_size(Splatter) > Splatter_Count){ // If more than allowed amount of items on list
do { // Start a loop.
ds_list_delete(Splatter, 0); // Delete the oldest list item, which is at position zero. This moves the remaining entries up by one step, so second-oldest will be at position zero after this.
} until(ds_list_size(Splatter) <= Splatter_Count); // Keep looping until list only has allowed amount.
}


//draw
for(var i = 0; i < Splatter_Count; i++)
{
var Blood = Splatter[| i];
if (Blood == -1) show_debug_message("illegal entry");
if (!is_array(Blood)) show_debug_message("not even an array");

draw_sprite(spr_blood, 0, Blood[0], Blood[1]);
}

obj_blood_splatter //blood object

//create
speed = random_range(0, 15)
direction = random_range(0, 360)
alarm_set(0, 10);

//collision with wall
// When the blood splatter stops:
My_Position = []; // Create an array.
My_Position[0] = x; // Store x position to first slot.
My_Position[1] = y; // Store y position to second slot.
ds_list_add(obj_blood_decals.Splatter, My_Position); // Add the array into the control object's list.
instance_destroy(); // The blood instance is no longer needed now.
 

Simon Gust

Member
I think I see it now.

In the draw event, you are looping from 0 to slatter_count, which at start is 100.
But the list has not been filled at all, so it tries to read 100 emtpy list entries.

You should only ever loop to ds list size.

DRAW EVENT
Code:
var size = ds_list_size(Splatter);
for(var i = 0; i < size; i++)
{
    var Blood = Splatter[| i];
    draw_sprite(spr_blood, 0, Blood[0], Blood[1]);
}
And hopefully, you won't get the error this time.
 
S

stepup2000

Guest
I think I see it now.

In the draw event, you are looping from 0 to slatter_count, which at start is 100.
But the list has not been filled at all, so it tries to read 100 emtpy list entries.

You should only ever loop to ds list size.

DRAW EVENT
Code:
var size = ds_list_size(Splatter);
for(var i = 0; i < size; i++)
{
    var Blood = Splatter[| i];
    draw_sprite(spr_blood, 0, Blood[0], Blood[1]);
}
And hopefully, you won't get the error this time.
dude you are amazing, thank you so much it finally works!
 
F

Finn

Guest
You might also want to read into particle effects for blood effects; they are not that hard to code up and can add very nice visual effects.
 
Top