Shadow character flickers

Started by Ashera, Thu 14/07/2005 21:38:15

Previous topic - Next topic

Ashera

I'm using a character as a shadow for the player character, but it flickers when it moves. It seems to be repeatedly switching between the frame it should be on and its "standing" frame. My AGS 2.62 code for the shadow worked without flickering, but when I switched over to 2.7-style code, it stopped working. When I did get the shadow working, it was only with the flickering effect.

Code: ags

function game_start() {
    ...
  
    // Shadow setup
    SetCharacterBaseline(SHADOW, character[EGO].y-1);
    SetCharacterTransparency (SHADOW, 50);
    game.following_room_timer = 1;
    cShadow.LockView(SHADOWTEST);
    
    ...
}


Code: ags

function repeatedly_execute_always()
{
    ...
    // Shadow control
    // Is the player on a walkable area (i.e. in a normal, non-puzzle room)?
    if (GetWalkableAreaAt(cEgo.x, cEgo.y) != 0)
    {
        cShadow.loop = cEgo.loop;
        cShadow.frame = cEgo.frame;
        cShadow.FollowCharacter(cEgo, FOLLOW_EXACTLY,  1);
    }
    else
    {
        // Use transparent loop to hide shadow
        cShadow.loop = 8;
    }
    ...
}

strazer

#1
I've tested it in a default 256-color game and there was no flickering. Maybe some of your sprites are the wrong color depth or your views are set up wrong?
Perhaps there's something else in your rep_ex that messes with this?

Anyway, a few notes about your code:

Quote
    SetCharacterBaseline(SHADOW, character[EGO].y-1);

This should be put into the rep_ex function because any baseline other than 0 is not relative to the character's position. If you set it to a certain value, the baseline will be fixed at this height and not automatically be updated when the character moves.

Btw, to be fully AGS v2.7 compliant, you'd better use v2.7 code:
  cShadow.Baseline = cEgo.y - 1;

Quote
    SetCharacterTransparency (SHADOW, 50);

  cShadow.Transparency = 50;

Quote
    game.following_room_timer = 1;

Don't characters set to FOLLOW_EXACTLY enter the shepherd's room immediately anyway? I don't think you need this in this example.

Quote
    cShadow.LockView(SHADOWTEST);

The LockView function is supposed to be used before animating a character. Since your shadow character is using this view the whole time, better use the Character.ChangeView function or set the SHADOW character to the SHADOWTEST view in the editor and remove this line.

Quote
        cShadow.loop = cEgo.loop;
        cShadow.frame = cEgo.frame;

To make your code fully v2.7-compliant, you should use the capitalized properties .Loop and .Frame.

Quote
        cShadow.FollowCharacter(cEgo, FOLLOW_EXACTLY,  1);

There's no need to call this function every game loop. It is supposed to be executed once, AGS will take care of the rest.

So, in conclusion, a cleaned-up version of your code would be:

Code: ags

function game_start() {
    //...
 
    // Shadow setup
    cShadow.Transparency = 50;
    cShadow.FollowCharacter(cEgo, FOLLOW_EXACTLY,  1);
   
    //...
}


Code: ags

function repeatedly_execute_always() {
    //...

    // Shadow control
    // Is the player on a walkable area (i.e. in a normal, non-puzzle room)?
    if (GetWalkableAreaAt(cEgo.x, cEgo.y) != 0) {
        cShadow.Baseline = cEgo.y - 1;
        cShadow.Loop = cEgo.Loop;
        cShadow.Frame = cEgo.Frame;
    }
    else {
        // Use transparent loop to hide shadow
        cShadow.Loop = 8;
    }

    //...
}


Hope this helps.

Edit: Spelling

GarageGothic

#2
I think that the problem is this line:
if (GetWalkableAreaAt(cEgo.x, cEgo.y) != 0)

cEgo.x and cEgo.y isn't totally exact, so when you move along the edges of the area, the sprite would flicker. I've had the same problem with GetAreaScaling. You'd be better off just to check if (player.Room == cShadow.Room) and just not move the shadow character to the rooms where you don't want to use him.


Also, I can't think of very many situations where you'd need a floor shadow to appear on top of another object (only if you had a moveable rug or manhole cover or something), so you might as well set the baseline to 1 once and for all. That also allows you to use a walkbehind as a "shadow mask" for any area where you don't want it to be drawn.

SMF spam blocked by CleanTalk