• 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!

GameMaker Trouble with Collision Masks of Sprites Created from Surfaces

I'm attempting to test a gameplay concept of erasing parts of a solid object to provide a path through. While I have managed to use surfaces to erase parts of the sprite's physical appearance, attempting to use sprite_collision_mask on the sprite created from the surface results in the same collision mask as before and the player object being unable to move through them. Since the function's manual page states it only works on duplicated sprites, I tried duplicating the object's base sprite, adding the new frame from the surface, and setting the image_index to it, with no change.

Does anyone know how to set the collision mask for the new sprite so that the player can move through the erased part?

The test so far:
https://mega.nz/#!mwgWgTKC!RHuCfG5EoSxRjpbif33I4-dfvPSplmRqnAZ6gO0u-h4
Arrows to move (tank controls), click and drag left mouse to erase, click button to reset
 
It's been a few days and I honestly think this won't get a response without a bump at the current rate. Attempted another approach with no success. Even though the mask_index is by all means getting the updated sprite, the actual collision mask remains unchanged. This would probably be a lot easier if there was a way to change or remove subimages from a duplicated sprite.

Here's the attempt, in the obj_eraser_action collision for obj_wall_erase:
Code:
/// @description erase the wall
var newsprite = surface_create(view_wport[0], view_hport[0]);
surface_set_target(newsprite);
draw_clear_alpha(c_black,0);
draw_sprite(sprite_index,0,x-view_xport[0],y-view_yport[0]);
gpu_set_blendmode(bm_subtract);
draw_sprite(other.sprite_index,0,view_xport[0],view_yport[0])
gpu_set_blendmode(bm_normal);
surface_reset_target();
var temp = sprite_duplicate(reference);
/*sprite_add_from_surface(temp,newsprite,x-view_xport[0],y-view_yport[0],
    sprite_get_width(reference), sprite_get_height(reference),
    false, false);*/
var temp2 = sprite_create_from_surface(newsprite,x-view_xport[0],y-view_yport[0],
    sprite_get_width(reference), sprite_get_height(reference),
    false, false,0,0);
sprite_assign(temp, temp2);
sprite_collision_mask(temp, true, 0, 0, 0, 0, 0, 0, 0);
sprite_assign(sprite_index, temp);
image_index = 1;
mask_index = sprite_index;
sprite_delete(temp);
sprite_delete(temp2);
surface_free(newsprite);
EDIT: I just tried using a wall sprite with a gap in it already and couldn't go in that gap. So I put a sprite_collison_mask over it just like in the code above only applied to the duplicate in sprite_index and it worked fine - until I drew over it and it became a solid rectangle again. Then I reset it and I couldn't enter the gap again. This is so confusing...
 
Last edited:
An update: I managed to figure out how to solve my initial problem! You needed to use sprite_collision_mask on sprite_index after assigning it from temp. It doesn't carry over from temp.

However, in my attempt to expand the concept further, I now have a new related problem. This is the opposite: a pass-through wall you paint over to make it solid. Since the wall doesn't have a collision box when it starts, it uses a slave object to handle brush collision. However, even though I use a similar structure to how I solved the other problem, the wall's collision mask won't change when sprite_collision_mask is called. Even setting it up so the wall itself rather than the slave object is running the code does nothing, nor does manually defining the bounding box. Is there something I'm missing here? What's the difference between the erasable wall and the fillable wall such that the former adjusts its mask while the latter doesn't?

Updated project:
https://mega.nz/#!exxSVJqT!vyRPgzovvWZNEXpDaBvveA49wUO4pi0HeGH6xjQNeE0
 
Top