Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dervish on Sun 09/09/2007 19:53:32

Title: Inverting the colours of the character sprite
Post by: Dervish on Sun 09/09/2007 19:53:32
I am doing a black and white game and I was wondering is there something with AGS similar to a walkbehind area where if the character walks into the specific area it will invert the black and white giving a simple light and shadow technic.
Title: Re: New and just had a question about inverting the character spirte
Post by: Recluse on Sun 09/09/2007 20:16:49
As of right now AGS doesn't have any native shadow rendering tools... If you're looking for a negative effect you might want to look into the RawDraw function and do a Google search for the algorithms to invert colors.

But to answer your question, there are no lighting functions native to AGS.
Title: Re: New and just had a question about inverting the character spirte
Post by: Dervish on Sun 09/09/2007 20:35:30
So if I made a negative sprite could I create a hotspot which replaced certain areas in the light with the negative sprite not the whole character mind you just the parts in the hotspot.
Title: Re: New and just had a question about inverting the character spirte
Post by: Scummbuddy on Sun 09/09/2007 23:32:15
If you mean, when a character walks onto a Region, not a hotspot, and that causes the background image to change, then I would suggest making a new background image, and change the background image, if player character is on top of region, and you could also change the player character view to one that is inverted.

Is there something else I'm not understanding from your question? Any other questions?
Title: Re: New and just had a question about inverting the character spirte
Post by: Khris on Mon 10/09/2007 00:53:39
I think Dervish wants to invert the colors of the part of the sprite that's touching the hotspot.
It's theoretically possible but would be incredibly slow.
Title: Re: New and just had a question about inverting the character spirte
Post by: BOYD1981 on Mon 10/09/2007 01:59:17
if it is actually just black and white (as in not greyscale) you could give your character a white outline (if it's black) and draw all your room's lines on the walkbehind layer (this would prevent the white outline obscuring lines you don't want it to) then when you walk onto a black area that is actually on the background the white outline would be visible.
Title: Re: New and just had a question about inverting the character spirte
Post by: Dervish on Mon 10/09/2007 02:10:14
KhrisMUC I think you have the idea
basically imagine a pitchblack room with light coming in through a window  displayed on screen by a white rectangle on the floor.  As the character walked into the square or the path of ligth from the window he would become highlighted  not his whole body but the part that was standing in the light.  ( I am talking strictly 2-d here).  I want ot know is there any feasible way & without hindering preformance that this could be done?
Title: Re: New and just had a question about inverting the character spirte
Post by: RickJ on Mon 10/09/2007 06:29:45
There are a couple of things you could try.

1.  Flashlight Plugin - I think the flash light plug-in may be able to do something like this. 

2.  Transparency Property - Objects and characters can be made translucent by setting the transparent property to a value between 0% and 100%.  Why couldn't you use a character or an object for your walk behind area.  Set it to 50% transparent and when the character walks behind it he will be seen through the now translucent object or character.  If you use a character as the walk-behind area then you can also change the character's tint.

3.  Regions - Regions have a lighting effect but I believe those affect the entire character.  However, you may want to review and experiment a bit as this  will produce something similar to what you are asking and is what is commonly used.

Let us mknow how it turns out for you.  Cheers
Title: Re: New and just had a question about inverting the character spirte
Post by: Khris on Mon 10/09/2007 09:20:45
I'm afraid neither of those are going to work. Not sure how 1 might do, but 2&3 affect the whole character.

The only "quick" way I can think of is to use manually drawn outlines.
The line's center (found by (x1+x2)/2 : (y1+y2)/2) determines the color of the line.

You'd have to make the character transparent, then do something like this:
function Line(x1, y1, x2, y2) {
  int x=player.x;
  int y=player.y;
  x1+=x;
  x2+=x;
  y1+=y;
  y2+=y;

  Hotspot*h=Hotspot.GetAtScreenXY((x1+x2)/2, (y1+y2)/2);
  if (h.ID==1) RawSetColor(1,1,1);
  else RawSetColor(255,255,255);

  RawDrawLine(x1, y1, x2, y2);
}

function DrawPlayer(int l, int f) {
  if (l==0) {
    if (f=0) {
      Line(-5, -70, 5, -70);
      ...
    ...
  ...
}

// inside rep_ex
  DrawPlayer(player.loop, player.frame);
Title: Re: New and just had a question about inverting the character spirte
Post by: RickJ on Mon 10/09/2007 21:57:08
KhrisMUC you are correct in that #3 would affect the entire character however I believe that you misundersttod option #2 I presented so I will attempt to clarify it.

From Dervish's description it seems that he would like a character to walk into or out of a shadow and so change the lighting effect of the player character.  This could be accomplished by doing the following. 

1. Draw the background with the shadow, (i.e. the places in shadow are drawn with normal lighting effects. 

2.  Draw the each contiguous shadow area  seperately, either on seperate layers or in a  seperate file, as a solid shape.

3.  Corp and export each shadow area to a seperate file and import each into the AGS sprite manager. 

4.  Create a room and import the background image.

5.  Create an object for each shadow image.  Set each object's image to the appropriate sprite created above.

6.  Set each object's position  relative to the background so that the shadow area is in the desired location.

7.  Set the object's baseline and walk-behind properties so that the player can walk behind it.

8.  Experiment with the object's transparency property and the color of the object's sprite until you get a satisfactory effect.

9.  The alpha blending features of AGS may also be helpful for this but it seems a bit of overkill to use 32-bit color for a black and white game.

Using this method the character will seem to be shaded when he walks behind a shadow object because he will be partially visible through the transparent object.  If the player character is positioned so that he is only partially behind the shadow object then only that portion will be visible through the transparent object and the rest will be visible as it normally is.

In my original description above I suggested that characters could be used instead of objects to produce the shadow effects.  This has the advantage of being able to change the characters tint as well as it's transparency from the script.





Title: Re: New and just had a question about inverting the character spirte
Post by: Khris on Mon 10/09/2007 22:29:45
Dervish, just to clarify, are we talking about pure black&white or gray-scale?

I imagined something like this:
(http://img210.imageshack.us/img210/9526/expldernh6.png)

The char (left) will lose part of his shape when touching the white spot (middle), so he's inverted (right).

I don't see how this effect could be created using transparent stuff, but I could be wrong.
Title: Re: New and just had a question about inverting the character spirte
Post by: Dervish on Tue 11/09/2007 03:33:03
yeah that is what I was looking  and it is blakc and white
Title: Re: New and just had a question about inverting the character spirte
Post by: RickJ on Tue 11/09/2007 09:11:25
Hehe, KhrisMUC, it seems I am the one who misunderstood what Dervish  is trying to do.   :=
Title: Re: New and just had a question about inverting the character spirte
Post by: GarageGothic on Tue 11/09/2007 11:19:15
Well, if all screens look like what KrishMUC posted, one way could be to have two character overlaying eachother:

One with only the black parts of the character, one with only the white (possible including a thin black outline surrounding the white lines). The rest of each character would be transparent. By using walkbehinds and baselines you could then have the black character drawn behind any bright on-screen area. This of course doesn't achieve a realistic light effect, but it could replicate KrishMUC's picture.

Edit: In using this technique, the white character must be set to always be drawn on top of walkbehinds. But possibly you could change this using regions in the area where the effect is actually needed.
Title: Re: New and just had a question about inverting the character spirte
Post by: Ashen on Tue 11/09/2007 22:57:43
This is the way I'd do it. It's similar to GarageGothic's method, but (if I've understood properly) should be nearer what your after. (GG, I don't see how just spliting the character into black bits and white bits would get the inversion effect Khris' image shows.)

Have two characters: one 'positive' in black and white (call him cEgo), one 'negative' in white and black (cOge). Use FollowCharacter, and the FOLLOW_EXACTLY parameter to have cOge match cEgo's position, drawn behind him. Set cOge to ignore Walkbehinds. You'll also need to do some stuff in the Global rep_ex, to match Loop and Frame (if you need it to match Talking views, animations, etc, it gets a bit more complicated. One thing at a time, though...).

Now, because cOge ignores walkbehinds, you should get the inverted look of Khris' right-most figure. Use Regions to have cOge pay attention to Walkbehinds, if you want the character to be fully hidden. Swap them around (cOge is always in front and cEgo ignores walkbehinds, or just change the Views over) for the other lighting effect.

Test Game (http://ashen.webng.com/BWTest.zip), to see if I'm in the right area. (Ctrl-X to move between rooms.)
Title: Re: Inverting the colours of the character sprite
Post by: GarageGothic on Wed 12/09/2007 00:22:12
Oh yeah, I hadn't looked at Khris' picture properly, I thought the white parts were just shining through. Anyway, the technique is the same, and it's even easier to do just an inverted character. Good solution.
Title: Re: Inverting the colours of the character sprite
Post by: Dervish on Thu 13/09/2007 06:13:37
Thanks guys.  I guess my only issue whould be having two characters grouped together might hinder performance of the game?  Thanks for all you guys ideas though.  I never figured I would get this many contribution to my problem.

Thanks
Title: Re: Inverting the colours of the character sprite
Post by: Dervish on Thu 13/09/2007 13:40:15
Ok I think I am gonna try something a little different. Let me know if anyone thinks this is possible.

I am going to use an Object and with every other pixel in the object being white and the other pixel a transparent color. 

My question then would be within an object is there anyway to get it to show up only on the character and not the background so that I would only get the pixelly light on the character and not covering the length from the window to the floor.
Title: Re: Inverting the colours of the character sprite
Post by: Khris on Thu 13/09/2007 13:51:28
In short: No, not directly.

Dynamically cropping an object can be achieved using RawDraw, DynamicSprites and Baselines, the usual stuff.
Title: Re: Inverting the colours of the character sprite
Post by: GarageGothic on Thu 13/09/2007 16:22:24
Two characters grouped together shouldn't cause any slowdowns. You can have 30+ characters on-screen at the same time without a framerate drop, at least in 320x240 resolution.