HTML5 How to change the collision mask of sprites ?

M

Mathieu

Guest
Hello.

To avoid memory problems with the target platform, all my game's sprites are included files.
When a level starts, the needed sprites are loaded (with "sprite_add") and when the level ends, they are deleted (with "sprite_delete").

But I would like to edit the default collision mask of some sprites (in particular sprites with sub-images because their default mask seems to be the whole sprite sheet size used).

I usually use "sprite_collision_mask" but it has no effect as written in help manual.

Thanks in advance for your help.
 
M

Mathieu

Guest
You could just use the 'mask_index' variable to set the mask yourself using a precreated sprite for that purpose.
Thank you for your answer, it works.
But it's a vicious circle : in order to correctly use included sprites instead of precreated sprites, I have to use precreated sprites...
 

TheouAegis

Member
Did you do it exactly as the manual said?

var spr = sprite_add(blahblahblah);
sprite_collision_mask(spr, blahblahblah);
sprite_index = spr;

You can post your code to show if you're using it right. However, it's also possible the issue is just with HTML5 or that you're using incompatible file types.
 
M

Mathieu

Guest
Here is my complete code :

When the player chooses "New game" for example, sprites used in chapter 1 (1 chapter = 3-4 rooms) are loaded with "load_sprites(1)".

"load_sprites()" Script code :
switch(argument0)
{
case 1 :
global.s_character1=sprite_add("character1.png", 4, false, false, 0, 0);
sprite_collision_mask(global.s_character1, true, 0, 0, 0, 0, 0, 0, 0);
global.s_character2=...
[...]​
break;
case 2 :
[...]​
}​

And in the Create Event of the object "o_character1" :
sprite_index=global.s_character1;

As I said in my first post, finally "o_character1" has no collision mask at all (even if I change the kind of bbox or mask to use).
And if I remove "sprite_collision_mask(...)", "o_character1" has a collision mask with the size of the complete sprite sheet (i.e. the sprite sheet is 40*40 so "s_character1" is a 10*40 sprite with 4 sub-images but finally it has a 40*40 collision mask by default).
 

TheouAegis

Member
What if you set the removeback flag in sprite_add to true?
Try setting argument1 in sprite_colliison_mask to false.
Make the left, top, right, bottom values 0, 0, 9, 39 respectively. Maybe they need to be set by default.
Your PNG could be the wrong format. I've had issues with them before.
 
M

Mathieu

Guest
What if you set the removeback flag in sprite_add to true?
Try setting argument1 in sprite_colliison_mask to false.
Make the left, top, right, bottom values 0, 0, 9, 39 respectively. Maybe they need to be set by default.
I've tried all possibilities (["removeback" to true + "argument1" to false + set values], ["removeback" to false + "argument1" to false + set values], etc...) but there is no effect.

Your PNG could be the wrong format. I've had issues with them before.
Do you mean the "PNG type" (for example an interlaced PNG) or the "file format" (for example to use JPEG instead) could be the problem ?
Because I have PNG files in order to use transparency.
 

TheouAegis

Member
I think i had better luck with gifs, but yeah (non)interlaced PNGs.
It could also just be HTML5. I didn't have issues with setting the collision properties on Win10 (but sprite_add did give me troubles).
 
Top