One of the equations that I used in Hindsight that really made the game work was the equation I came up with for the blocks to fade in and out. However, it has more uses than just that. For instance, if you want text to fade in and then out as the player gets closer and then further from a certain object, like I did with some of the text in Hindsight, you can do that pretty easily, too.

You can set distance to whatever value you want in the create event of the object.

Create:
distance = 100; 

Then, the code below makes things fade out as you approach them. If you are not within the set range, it will make sure that the object is completely invisible. The equation itself is very simple — because of the if statement, the distance to the object will always be less than the value of your distance variable. It then divides the values. If obj_player was 32 pixels away from whatever this object is and distance was set to 100, then 32 divided by 100 is equal to 0.32. And, since image_alpha has to between 0 and 1, this value works perfectly fine. If obj_player’s distance to the object was equal to 95, then 95 divided by 100 equals 0.95, which not only works with image_alpha but also does the desired effect.

Step:
if distance_to_object(obj_player) <= distance
          {image_alpha = distance_to_object(obj_player) / distance}
else
          {image_alpha = 0}

Now, what if you wanted to do the same thing as above but make it fade in as you approach, instead of out? This is a little bit trickier, but follows the same idea as the other equation initially. However, you need to divide by the opposite of distance and then add 1 to the answer of the division. If obj_player is 10 pixels away, then 10 divided by -100 equals -0.10. Then if you add 1 to it, it will equal 0.9, which is what we want. Or, if obj_player is 85 pixels away, divide 85 by -100 and then add  1 to the answer of that and you get 0.15, which is also what we want.

Step:
if distance_to_object(obj_player) <= distance
          {image_alpha = (distance_to_object(obj_player) / -distance) + 1}
else
          {image_alpha = 0}

Now that I’ve fulfilled my goal of a blog post for today, I’m going to sleep. Good night.

-Nathan Wood

Advertisements

About turboRamble

I am a seventeen-year-old who enjoys programming games and applications, as well as reading and writing.

2 responses »

  1. Does your blog have a contact page?
    I’m having trouble locating it but, I’d like to shoot you an e-mail.

    I’ve got some recommendations for your blog you might be interested
    in hearing. Either way, great blog and I look forward to seeing it expand over
    time.

  2. Benjamin says:

    scr_text(“Thank You, This Helped Me A Lot” , 10, true)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s