Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: WHAM on Wed 09/02/2011 20:46:33

Title: Object flickering when displayed over player sprite
Post by: WHAM on Wed 09/02/2011 20:46:33
Here's a little bit of code:


function room_RepExec()
{
if (integerthatgoesupeverytenseconds >= 1 && cEgo.Moving == true && oWheetWhoot.Visible == false) {
   oWheetWhoot.Visible = true;
   oWheetWhoot.Y = 169; // cEgo walks on Y 199
   oWheetWhoot.X = cEgo.x - 13; // Makes oWheetwhoot float over cEgo sprite
} else {
   oWheetWhoot.Visible = false;
}
}
// oWheetWhoot is animated all the time (eRepeat)


I tried removing the checks for cEgo.Moving and oWheetWhoot visibility, and when cEgo remains in place, oWheetWhoot is shown correctly. BUT: when cEgo walks left or right, the object seems to flicker.

Any ideas on the cause? Ways this could be improved?
Title: Re: Object flickering when displayed over player sprite
Post by: Khris on Wed 09/02/2011 22:30:15
The object flickers when cEgo is walking -> cEgo.Moving == true
Thus, assuming that the integer that goes up is >= 1 most of the time, what's left is:

  if (object is visible) make it invisible
  else make it visible


In other words, all the code does is make the object flicker.
Title: Re: Object flickering when displayed over player sprite
Post by: Unai on Thu 10/02/2011 07:19:47
What should the WheetWoot exactly do and when?

I agree with Khris that script would make the object flicker, but is hard to propose a fix without knowing what and when it's supposed to do... :S
Title: Re: Object flickering when displayed over player sprite
Post by: WHAM on Thu 10/02/2011 07:23:02
I tested this script in the following form:

function room_RepExec()
{
if (integerthatgoesupeverytenseconds >= 1) {
   oWheetWhoot.Visible = true;
   oWheetWhoot.Y = 169; // cEgo walks on Y 199
   oWheetWhoot.X = cEgo.x - 13; // Makes oWheetwhoot float over cEgo sprite
} else {
   oWheetWhoot.Visible = false;
}
}[code]

The flickering still takes place when cEgo is walking around. The only variable being checked receives a
[code]
integerthatgoesupeverytenseconds++;

every ten seconds or so.

Also, doesn't the cEgo.Moving return "true" when cEgo is walking? Or am I misunderstanding its purpose?

@Unai: oWheetwhoot is a small object that floats on the main character at roughly knee-level and loops a simple animation. It is supposeed to be visible only when cEgo moves, otherwise it is not visible. Think of an object being used as an overlay to simulate a character's feet kicking up dust as he/she walks.[/code][/code]
Title: Re: Object flickering when displayed over player sprite
Post by: Calin Leafshade on Thu 10/02/2011 08:11:12
i'm confused.

shouldnt this be simply


if (player.Moving) oWheetWhoot.Visible = true;
else oWheetWhoot.Visible = false;

Title: Re: Object flickering when displayed over player sprite
Post by: WHAM on Thu 10/02/2011 08:33:31
Quote from: Calin Elephantsittingonface on Thu 10/02/2011 08:11:12
i'm confused.

shouldnt this be simply


if (player.Moving) oWheetWhoot.Visible = true;
else oWheetWhoot.Visible = false;


In all intents and purposes, isn't that basically the same thing I'm trying to do, but written without the "{" and "}":s? How does that function differently than my:


if (cEgo.Moving == true) {
    oWheetWhoot.Visible = true;
    oWheetWhoot.Y = 169; // cEgo walks on Y 199
    oWheetWhoot.X = cEgo.x - 13; // Makes oWheetwhoot float over cEgo sprite
} else {
    oWheetWhoot.Visible = false;
}


It's those

    oWheetWhoot.Y = 169; // cEgo walks on Y 199
    oWheetWhoot.X = cEgo.x - 13; // Makes oWheetwhoot float over cEgo sprite

lines that I'm worrying about now. To me it feels like they are causing the flickering for some reason. I'll just have to get back to testing to see if I can get it to work once I get back home.
Title: Re: Object flickering when displayed over player sprite
Post by: Khris on Thu 10/02/2011 08:54:24
Quote from: WHAM on Thu 10/02/2011 08:33:31In all intents and purposes, isn't that basically the same thing I'm trying to do

No it's not.
As I explained, provided that we leave out the counter for now and the player is currently moving, what's left is
pseudo  if (object is invisible) make it visible
  else make it invisible

Look:
  if (integerthatgoesupeverytenseconds >= 1 && cEgo.Moving == true && oWheetWhoot.Visible == false)
That's the test you're doing, and it'll successfully turn on oWheetWhoot. But immediately afterwards, in the subsequent game loop, this condition is no longer true, since oWheetWhoot.Visible is no longer false.
Thus, due to your else, oWheetWhoot is turned invisible. Rinse, repeat.

If you're actually using the code in your last post, there shouldn't be any flickering.
And of course, changing the coordinates doesn't cause flickering "for some reason". We've told you what does it.
Title: Re: Object flickering when displayed over player sprite
Post by: WHAM on Thu 10/02/2011 09:13:29
Aaaaah! Now I see! I was just being a dunce about this!
I misunderstood your first post and was, apparently, too blind to realize what you were trying to say.

I'll fix this as soon as I get back home, thanks again!
Title: Re: Object flickering when displayed over player sprite
Post by: Unai on Thu 10/02/2011 10:44:12
Ummm, couldn't you use a "WheetWhoot" character and FollowCharacter?
If the WheetWhoot has a walkin animation that shows it hovering when walking you should get that effect... Right?

It's all theory though, I never tried that...
Title: Re: Object flickering when displayed over player sprite
Post by: WHAM on Thu 10/02/2011 10:50:07
As fas as I know and have used the followcharacter, that command tends to lag behind, so it would not work quite as intended.