Jump to content


Photo

Creating and using a rectangular mask from w & h


  • Please log in to reply
5 replies to this topic

#1 Grundoko

Grundoko

    GMC Member

  • GMC Member
  • 566 posts

Posted 27 September 2010 - 01:08 AM

This seemed fairly simple to me at first, and I'm sure it's something very simple I'm missing, but I really can't figure this out.

I'm trying to give the player a rectangular collision mask based on it's width and height, so I create_sprite_from_screen to get a sprite from the screen the size of the player.
I then set the collision properties of it, and applied it to the player object using mask_index, but it's not working.

Here's the exact code I'm using.
// The width (in pixels) of the player
global.player_width = 30

// The height (in pixels) of the player
global.player_height = 30

// Set the mask to the given width and height of the player
mask_player = sprite_create_from_screen(x,y,global.player_width,global.player_height,0,0,0,0)
sprite_collision_mask(mask_player,0,1,0,0,0,0,1,0)
mask_index = mask_player

Any help would be appreciated.
  • 0

#2 Jakyl11

Jakyl11

    GMC Member

  • GMC Member
  • 3109 posts
  • Version:GM:Studio

Posted 27 September 2010 - 01:11 AM

why not try something more simple like collision_rectangle();?
  • 0

#3 Grundoko

Grundoko

    GMC Member

  • GMC Member
  • 566 posts

Posted 27 September 2010 - 01:14 AM

I need to use collision_line, and for that the object needs a collision mask.
  • 0

#4 Grundoko

Grundoko

    GMC Member

  • GMC Member
  • 566 posts

Posted 27 September 2010 - 05:42 PM

*Bump
  • 0

#5 Jakyl11

Jakyl11

    GMC Member

  • GMC Member
  • 3109 posts
  • Version:GM:Studio

Posted 27 September 2010 - 10:48 PM

first dont double post...
second your code works correctly you must be doing something wrong because it works for me.

edit: also are you calling this in the object thats using the mask?
if not theres your problem.

heres how it would look if your using in a different object to set another objects mask_index

// The width (in pixels) of the player
global.player_width = 30

// The height (in pixels) of the player
global.player_height = 30

with(obj_player)
{
mask_player = sprite_create_from_screen(x,y,global.player_width,global.
player_height,0,0,0,0)
sprite_collision_mask(mask_player,0,1,0,0,0,0,1,0)
mask_index = mask_player
}

Edited by Jakyl11, 27 September 2010 - 10:53 PM.

  • 0

#6 Grundoko

Grundoko

    GMC Member

  • GMC Member
  • 566 posts

Posted 27 September 2010 - 11:35 PM

I was indeed calling it in the object that needs to use the mask. In the create event. It works fine when using a pre-made mask (made before compile), but when I try using the code, the collisions no longer work.

EDIT: The code I wrote in my first post actually works fine. It turns out I had commented out the collision code earlier for testing, and so it was acting as if there was no mask, because it wasn't even checking for collisions -_-

I feel stupid :P

Edited by Grundoko, 28 September 2010 - 10:09 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users