Ok guys so finally I have found a solution: (Thanks to all of you guys specially to
jo-thijs and rIKmAN that help me in to this process)
I want to say that this solution works, maybe there are better ones using the bounding boxes in Spine but I didn't find anything that works as well as this solution at the moment, were are going step by step:
1. What do we want to do? As you can see(first post) we have an enemy and the player. The enemy has a sword and the enemy attacks the player and hurts him. So we need to create a bounding box in GMS2 that follows the sword bone.
Now we have create this in Spine we have to create a bounding box in our gms 2 project.
Create in GMS 2, one sprinte with the size of your bone and then create the objet in GMS2:
View attachment 19426
Now its' time to code. We want this bounding box to follow the bone sword coordinates(code made by
jo-thijs) :
Add to the create event of o_enemy the following:
Code:
sword_data = ds_map_create();
// In this code we create the ds_map called sword_data
Then add this code to the end step event:
Code:
ds_map_clear(sword_data);
skeleton_bone_state_get("SWORD", sword_data);
// In this code we are taking the data of the SWORD bone and put in in to the ds map called sword_data that we created.
Finally add this to the draw event:
Code:
var sword_x = x + sword_data[?"worldX"];
var sword_y = y + sword_data[?"worldY"];
draw_circle_color(sword_x, sword_y, 8, c_green, c_green, false);
var sword_angle = -bone_data[?"worldAngleX"];
draw_line_color(sword_x, sword_y, sword_x + lengthdir_x(8, sword_angle), sword_y + lengthdir_y(8, sword_angle), c_black, c_black);
// In this code we are setting the sword x position ( enemy x+ spine sword bone x) and the same with the y (enemy y postion+ spine sword bone y position). And drawing a circle to see it in the game (not neccesary)
then we are creating a variable that will be the sword angle (because we are taking the angle from Spine)
You should see a green circle following the sword handle, along with a black line inside the circle pointing in the same direction as the sword.
In this way, you can retrieve the position and direction of the sword in the end step event.
You can then use this to perform your own collision checks, instead of relying on the spine system.
For example, you could add a new sprite to your project that is just the sword with its collision mask (not as spine).
You can then have an invisible object follow the sword in the end step event and perform collision checks with the new sword sprite as mask.
Let's call this invisible object o_sword_mask and give it the sword sprite as mask.
You can then do the following in o_enemy:
add this to the create event:
Code:
sword_mask = instance_create_depth(x, y, 0, o_sword_mask);
// in this code we create the sword_mask instance in the enemy object.
put this in the destroy event:
Code:
instance_destroy(sword_mask);
// in this code just guarantees that when the enemy instance gets destroyed, the sword_mask instance following them also gets destroyed.It probably currently won't be doing anything in your project if enemies can't die.
put this in the other user defined event 0:
Code:
// Player (other) collided with sword
game_restart();
and add this to the end of the end step event:
Code:
with sword_mask {
x = other.x + other.sword_data[?"worldX"];
y = other.y + other.sword_data[?"worldY"];
image_angle = -other.sword_data[?"worldAngleX"];
}
with o_player {
if place_meeting(x, y, other.sword_mask) {
with other {
event_user(0);
}
}
}
Hope it helps!