Inverting the colours of the character sprite

Started by Dervish, Sun 09/09/2007 19:53:32

Previous topic - Next topic

Dervish

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.

Recluse

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.
All your verbcoin are belong to us.

Dervish

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.

Scummbuddy

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?
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Khris

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.

BOYD1981

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.

Limey Lizard, Waste Wizard!
01101101011000010110010001100101001000000111100101101111011101010010000001101100011011110110111101101011

Dervish

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?

RickJ

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

Khris

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:
Code: ags
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);

RickJ

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.






Khris

Dervish, just to clarify, are we talking about pure black&white or gray-scale?

I imagined something like this:


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.

Dervish

yeah that is what I was looking  and it is blakc and white

RickJ

Hehe, KhrisMUC, it seems I am the one who misunderstood what Dervish  is trying to do.   :=

GarageGothic

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.

Ashen

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, to see if I'm in the right area. (Ctrl-X to move between rooms.)
I know what you're thinking ... Don't think that.

GarageGothic

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.

Dervish

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

Dervish

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.

Khris

In short: No, not directly.

Dynamically cropping an object can be achieved using RawDraw, DynamicSprites and Baselines, the usual stuff.

GarageGothic

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.

SMF spam blocked by CleanTalk