Jump to content


Photo

image_blend alpha?


  • Please log in to reply
7 replies to this topic

#1 Lemoncreme

Lemoncreme

    GMC Member

  • GMC Member
  • 161 posts
  • Version:GM8

Posted 22 June 2012 - 12:02 AM

I'd like to know if there is a way to change the alpha for the function image_blend.
I'm re-doing the lighting system for my game, and this would be perfect for smooth lighting.

Please help or at least give feedback. :unsure:
  • 0

#2 Katuko

Katuko

    GMC Member

  • GMC Member
  • 4875 posts

Posted 22 June 2012 - 12:19 AM

Two ways:

1) Draw the regular sprite. Then draw the sprite again on top of itself with color blending, using draw_sprite_ext() to add both the blend and the alpha.
2) Set the blending color to merge_color(c_white,COLOR,FACTOR); where COLOR is the color you want and FACTOR is a number between 0 and 1.
  • 1

#3 Lemoncreme

Lemoncreme

    GMC Member

  • GMC Member
  • 161 posts
  • Version:GM8

Posted 22 June 2012 - 01:03 AM

Two ways:

1) Draw the regular sprite. Then draw the sprite again on top of itself with color blending, using draw_sprite_ext() to add both the blend and the alpha.
2) Set the blending color to merge_color(c_white,COLOR,FACTOR); where COLOR is the color you want and FACTOR is a number between 0 and 1.


That's great, except I need it to support more than one source of light.
For example, the "FACTOR" in my code is the distance to the object of the main character.
How can I have the distance to the character AND the distance to the mouse without the first one stopping the other?

But besides that, thank you.

And please respond.
  • 0

#4 Katuko

Katuko

    GMC Member

  • GMC Member
  • 4875 posts

Posted 22 June 2012 - 01:10 AM

It depends on how you want them to interact and what the result should be, but it boils down to some simple math involving point_distance() and similar functions.
  • 0

#5 Lemoncreme

Lemoncreme

    GMC Member

  • GMC Member
  • 161 posts
  • Version:GM8

Posted 22 June 2012 - 01:13 AM

It depends on how you want them to interact and what the result should be, but it boils down to some simple math involving point_distance() and similar functions.


Do tell.
  • 0

#6 Katuko

Katuko

    GMC Member

  • GMC Member
  • 4875 posts

Posted 22 June 2012 - 01:17 AM

I need more info regarding exactly what you want to happen between these objects and the mouse position. I can't just write code without knowing what it should do. :)
  • 0

#7 Lemoncreme

Lemoncreme

    GMC Member

  • GMC Member
  • 161 posts
  • Version:GM8

Posted 22 June 2012 - 01:28 AM

I need more info regarding exactly what you want to happen between these objects and the mouse position. I can't just write code without knowing what it should do. :)


Alright. Sorry.
What i would like to happen is for the object that uses your code:
image_blend=merge_color(c_white,COLOR,FACTOR)
With my variation to give an illusion of an object having brightness:
image_blend=merge_color(c_white,c_black,distance_to_object(Light)*0.005)
(0.005 is there so the light is larger.)
To also be lit or unlit by another object:
image_blend=merge_color(c_white,c_black,distance_to_object(Light_Other)*0.005)


The problem is that this doesn't work:
image_blend=merge_color(c_white,c_black,distance_to_object(Light)*0.005)
image_blend=merge_color(c_white,c_black,distance_to_object(Light_Other)*0.005)


What happens when I use the above is that the object being lit is only being lit by the second object, or "Light_Other".


(Also the mouse position was just another way of saying another object, they both work as coordinates)


So what I want is for the object using the code to be able to be lit by two or more objects.
  • 0

#8 Katuko

Katuko

    GMC Member

  • GMC Member
  • 4875 posts

Posted 22 June 2012 - 10:30 AM

Well, blending like that will have the second line overwrite the first, so that's normal. You'll have to calculate both distances and then add them together; making an average or something. It is at this point I realize I'm not entirely sure about the best way to do that. Possibly picking only the shortest distance for the light could work. Make a new object and call it "par_Light" or something. Set it as the parent for all of your light-giving objects.

var dist;
dist = distance_to_object(instance_nearest(x,y,par_Light));
image_blend = merge_color(c_white,c_black,dist*0.005);

Though if you want two lights at medium distance to be as bright as one light at close distance then I guess the factors will have to be calculated first.

var f1, f2, ff;
f1 = distance_to_object(Light)*0.005;
f2 = distance_to_object(Light_Other)*0.005;
ff = max(f1+f2,1);
image_blend = merge_color(c_white,c_black,ff);


By the way, you should probably pre- or suffix your code so it's easier to distinguish between sprites, objects etc. In code, especially, since having two resources with the same name causes issues. Example: Having "Cat" and "Cat" instead of "sprCat" and "objCat". Trying to create an instance of the cat object will make Game Maker use the sprite ID instead if they have the same name, thus spawning an entirely different object or no object at all.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users