2
\$\begingroup\$

My game has a Pokemon-type movement mechanic.

I would like my level was a pitch black level, but the player having a candle can lighten a circular area, and so walk without being able to see more than some near steps beyond him. I.e. not being able to see the whole map.

How can I acheve that in Gamemaker Studio?

Elements in my game:

  • A character, moving squarely tile by tile.
  • A wall. Just a wall.
  • A background for the floor.

The game is not about Pokemon, but think as if I'm using the same mechanics for movement. It also happens to be the same concept as the flash HM in a cave.

enter image description here

\$\endgroup\$
  • 4
    \$\begingroup\$ The easiest answer is a giant, screen-sized black texture (with a hole in the middle) that covers everything. \$\endgroup\$ – Draco18s no longer trusts SE Feb 10 '16 at 22:01
4
\$\begingroup\$

Assuming the camera follows the character, you should be able to use an image to black out all of the screen except around the character. If your game window is 800x600 for example, create a fully-black sprite that's also 800x600, find the center point of the sprite, then clear out a transparent circle around that point.

Been a while since I've used GameMaker, but IIRC, you need to use the "Draw" event. You should have a line of code inside the "Draw" event which constantly repositions the darkness sprite to the character's position. Another option would be to reposition the sprite every time the character moves.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ I will go for this approach. Wanted a cleaner one (e.g. foregrond black, and masking it with a sprite image), but seems this one is easier \$\endgroup\$ – Luis Masuelli Feb 10 '16 at 22:11
1
\$\begingroup\$

The best way to do this is to draw a surface across the entire screen (I usually draw it to the view, since it's more efficient and less hard on resources), and then use an image_blend in the draw event of your player character to draw the faded circle Peter posted centred at objPlayer.x, objPlayer.y, which will grant you greater control over the radius of light and allow you to add certain effects, such as flickering and radius changes, and change the colour of it easily without having to resprite it every time. The alternate is instead of having a sprite, you could just straight up use

draw_set_blend_mode(bm_add or bm_subtract, whichever one you want)

draw_set_colour(whatever colour you want)

draw_circle(arguments)

draw_set_blend_mode(bm_normal)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.