Jump to content


Photo

How to erase part of something drawn?


  • Please log in to reply
2 replies to this topic

#1 iPseudo

iPseudo

    GMC Member

  • New Member
  • 4 posts
  • Version:GM:HTML5

Posted 10 April 2012 - 01:42 AM

Alright so here's my situation:

I need a solid color(a filled rectangle), to be partly erased by drawing a circle on top of it, where the circle erases the solid color within it's dimensions.

But drawing a circle with an alpha of 0 would just not effect it at all, yeah?

...So how should I go about doing this?

EDIT: I'm doing this is GM: Studio, if that causes any issues.

Edited by iPseudo, 10 April 2012 - 01:48 AM.

  • 0

#2 filulilus

filulilus

    GMC Member

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

Posted 10 April 2012 - 06:37 AM

Im not sure if GM Studio suports surfaces but if it does then try this:


// CREAT EVENT
surfaceRectangle = surface_create(width, height)


// The following part can also be put in some other event if you like to update the size of the rectangle.
surface_set_target(surfaceRectangle)

// Draw the rectangle.
draw_set_color(c_red)
draw_rectangle(0, 0, width, height, 0)

// Remove a circle from the center of the rectangle.
draw_set_color(c_white)
draw_set_blend_mode(bm_subtract)
draw_ellipsoid(0, 0, width, height)
draw_set_blend_mode(bm_normal)
surface_reset_target()

// DRAW EVENT
draw_surface(surfaceRectangle, x, y)

What this does is that it will:
1. Draw a rectangle to a surface (a surface is kinda like a sprite which can be modified in real time).
2. Then it changes the blend mode so that when you draw the circle it will remove pixels from the surface rather then draw pixels.
3. Simply draw the surface anywhere on the screen.

Surfaces are really usefull in a lot of situiations such as light and shadow effects.
This is an example of what you can achieve:
Notice that the water is wavey and it's actually animated in real time, yet another example of what kind of power surfaces possess.
Posted Image

Edited by filulilus, 10 April 2012 - 06:57 AM.

  • 0

#3 iPseudo

iPseudo

    GMC Member

  • New Member
  • 4 posts
  • Version:GM:HTML5

Posted 10 April 2012 - 06:27 PM

ahhh. thank you very much:)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users