Life counter doesn't work with Direct3D!

Started by MaximusDecimus, Thu 03/11/2011 04:31:09

Previous topic - Next topic

MaximusDecimus

I have a life counter that shows different images when the player's hit points change. The function looks like this.

Code: ags

function DealLife() {

if(p.HP < 1) object[0].Graphic = 105; // empty life
else if(p.HP <= p.MaxHP * 5/100 && p.HP > 0) object[0].Graphic = 189; // more than 0 but less than 5% of max life
else if(p.HP <= p.MaxHP * 10/100 && p.HP > p.MaxHP * 5/100) object[0].Graphic = 104;
else if(p.HP <= p.MaxHP * 15/100 && p.HP > p.MaxHP * 10/100) object[0].Graphic = 188;
else if(p.HP <= p.MaxHP * 20/100 && p.HP > p.MaxHP * 15/100) object[0].Graphic = 103;
else if(p.HP <= p.MaxHP * 25/100 && p.HP > p.MaxHP * 20/100) object[0].Graphic = 187;
else if(p.HP <= p.MaxHP * 30/100 && p.HP > p.MaxHP * 25/100) object[0].Graphic = 102;
// etc.
else if(p.HP <= p.MaxHP && p.HP > p.MaxHP * 95/100) object[0].Graphic = 46; // full life
}


This works just fine when using DirectDraw. But, when I set it to Direct3D, the life counter appears to be full (at 100% HP) the whole time, apart from when the player dies (at zero HP). All the sprites in the middle are missing. By the way, I am not calling this function in repeatedly execute, it's called every time a monster hits the player.

Can you please tell me why things don't go like they should with D3D?


Gilbert

Try to re-import the sprites. It's a wild guess, that these sprites may be of a colour depth different to the game's. Normally the editor should convert the sprites on the fly when you import a sprite or change the colour depth of the game, but things may go wrong. It is possible that the D3D driver may fail to render graphics correctly if the resources aren't in the correct colour depth.

MaximusDecimus

#2
I made the sprites 16-bit, because the game is 16-bit, but it still doesn't work. Besides, the first and the last sprite of the counter had been showing before.
And it's not a scripting mistake as it works with DD5.

EDIT: Most of the other sprites are 32-bit, so I've changed everything to 32, but still no luck.

EDIT 2: The problem was somewhere else. I have an overlay which shows on death. It was overriding the life counter when using D3D. By playing around with BaselineOverriden, I managed to set it right so that it now works with both video modes. Thanks for your help anyway.  ;D

Khris

That code is pretty awkward, try this:

Code: ags
void DealLife() {

   int slot;
   if (p.HP < 1) slot = 0;
   else slot = ((p.HP-1)*20)/p.MaxHP+1;
   String slots = "105,189,104,188,103,187,102,...";   // put all slots in here, three characters for each, no spaces(!), 99 -> ,099,
   slots = slots.Substring(slot*4, 3);
   object[0].Graphic = slots.AsInt;
}


Even better: change the sprite slot numbers so that they're in order; slot will be a number from 0 to 20 so all that would be left to do is add an offset. If your sprites had slots 102-122, you'd just set object[0].Graphic to slot + 102, no need for the String business in that case.

On a side note, having 1 HP of say a max of 1000 being displayed as 5% isn't too great; how do those sprites look? Are they just colored bars? Because if there isn't too much eye candy, you could draw them on the fly, even using a sprite for the end of the bar if it's supposed to be rounded off or something. Way better than importing 21 sprites that more or less look the same.

deee

Nice to see that your problem is solved, but it seems to me that nobody should be using D3D anyways.
Nobody wants to play a game where everything gets dark on restarting the game. This bug seems to be unsolvable as seen in this thread:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=44442.0

I know this is a bit off-topic, but have you tried to restart the game in fullscreen mode and encountered the gamma problem ?
If yes, will you keep running it in D3D ?


MaximusDecimus

#5
I haven't encountered such problems, but thank you for telling me this. I will use DirectDraw from now on, in case something bad really happens with D3D. I've made this topic just because I was afraid that all other people used D3D.

LeKhris, your tips are well appreciated!


DoorKnobHandle

Quote from: deee on Thu 03/11/2011 11:56:30
[...] it seems to me that nobody should be using D3D anyways.

Please don't make it look like your specific problem (which could be due to a wide variety of reasons, outdated drivers or hardware failure for example) is more common than it is. There is not a single other person who experiences the same problem as you are. In fact, a lot of modern PCs and laptops running Windows 7 have trouble with the DirectDraw mode. Don't spread rumors to developers which could result in them being negatively affected! :)

MaximusDecimus

Exactly, DirectDraw doesn't work properly on my laptop. It wouldn't let the mouse move. But don't worry: I almost never use laptops for playing games.

deee

Thanks, dkh, you are giving me hope again :)
Yet I'm afraid, it is not my specific problem, as Khris said, there are some bugs like this one known in D3D, nobody seems to have a solution to it and I tried my game on several PCs with different hardware, though the problem persisted :(

D3D users, please share your personal experiences with gamma behaviour ;)
I didn't mean to negatively affect somebody, although I am negatively affected ;)
And I still prefer D3D over DD5, because of the smooth sprite appearance.


SMF spam blocked by CleanTalk