Sunday, March 30, 2014

Using BitmapData in Dynamic Glow Effects

A couple of posts ago, I talked about a small visual glitch with the dynamic glow effects. I was trying to use a red glow effect surrounding the different character portraits. Instead of drawing a glow effect in Photoshop for each portrait, I decided to use Flixel built-in blur effects to obtain the glow dynamically at run-time (saving lots of repetitive work and disk space). However, in order to fully emulate Photoshop's glow effect using Flixel blur, I needed to manipulate the actual pixels of the image in order to make them all white.
And that's were Flash low level functions started becoming handy. Just by accessing a Sprite's BitmapData you can manipulate all its pixels. Here's a small code snippet showing how I tinted my sprites in pure white color in order to solve the discontinous glow corner issue.

All in all, the result is pretty similar to Photoshop's glow effect.

However, low level pixel operations (iterating though all the pixels, modifying their color, etc) are GPU-intensive, so try to minimize them as much as you can. For instance, you can save all your modified sprites in variables or class fields for later reuse. And of course, now I can highlight not only the portraits but other objects in the game.

In Bloodhunt, most actions are influenced by the character sheet: movement, dialogs and item selection. In order to interact with an item (such as the selected bed in the screenshot above) your character should meet two requirements:

  1. Your character Inspection feat (Perception + Investigation) should be greater or equal to the item requirement. The bed in the example requires 1 point of Inspection, which means that all characters can select it since all vampires start the game with 1 point of Perception. However, other items such as the nightstand or the radio require 3 or more points of Inspection which means that some characters just can't interact with them. So you won't know what's inside the nightstand unless you've spent at least 2 free points rising your Inspection feat. 
  2. Your character should be inside a radius proportional to Perception. Characters with low Perception are forced to walk in the room until they are close to each object. Characters with high Perception are able to see all the objects in a room without walking around. This affects not only items but NPCs and enemies alike, which gives an interesting strategic advantage based on Perception.

No comments:

Post a Comment