Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Progress bar alongside 3d object

Author
Message
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 8th Jun 2011 13:05
Hi everyone,

I was wondering how you would go about displaying a 2D image along side a 3D object. I am making an RTS game, and this would be needed in it to show things such as build progress of buildings, health of units and promotion of units.

This only issue is that I can begin to think how I would go about this efficiently... If anyone could help out it would be greatly appreciated.

Below is an image to clarify what I mean by these bars;



A

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Jun 2011 13:38 Edited at: 8th Jun 2011 13:40
You can do this quite easily actually by getting the object's position on screen:

...then just position a bar above the object.

Here is some sample code:


EDIT: This code could be made more efficient but it works...

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Jun 2011 13:46 Edited at: 8th Jun 2011 13:47
I would just use a sprite - maybe 2 - one for the backing, and one for the bar. The box selection around each unit would have to be a plain, but the little bar should be easy enough to impliment...



Then once you've done all the units, maybe clean up the sprites...



That sort of thing - assuming that your bar is 64 pixels wide, and globalise the spr_no variable so the function can keep track. You could even use PASTE SPRITE to avoid having lots of sprites to manage, like just 1 sprite for the backdrop which is pasted, and another sprite for the bar which is sized then pasted. You could even just draw a box, but drawing boxes in DBPro is pretty slow so I wouldn't recommend that.

Health, Ammo, and bacon and eggs!
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Jun 2011 13:54
Quote: "drawing boxes in DBPro is pretty slow so I wouldn't recommend that."

Actually you're right for an RTS you would need to use Cloggy's d3d plugin for drawing boxes. Your method would be much quicker anyway, just resize the sprite used for the percentage of health before pasting it. Nice idea.

I only ever used that code for one or two bars at any one time (using d3d).

Looks like I'm going to have to make a new faster version...

A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 8th Jun 2011 14:43
How about an animated sprite? It would then be able to manage a progress bar, promotion level and any thing else I ask of it. Just set the frame of the sprite manually, rather than playing it through in a controlled fashion. I could that way, manage any teams health and any promotion level in a single sprite and function command.

These two commands are a god send! I wasn't aware of their existence else I imagine it wouldn't have been a problem to manage this feature;



I'll post a video of this feature along with the others once I solve why my new advanced terrain is causing issues for object placement.

A

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 8th Jun 2011 18:22
Quote: "How about an animated sprite? It would then be able to manage a progress bar, promotion level and any thing else I ask of it. Just set the frame of the sprite manually, rather than playing it through in a controlled fashion. I could that way, manage any teams health and any promotion level in a single sprite and function command."


That would work if you had one animated sprite, change the sprite frame, and use PASTE SPRITE. A 100 frame animated sprite would make it easier on you since 100% health would be frame 100. I suggest keeping the current sprite frame for each unit in a UDT though (no need to calculate the health every loop).

Login to post a reply

Server time is: 2026-07-10 22:54:04
Your offset time is: 2026-07-10 22:54:04