Sign in to follow this  
alieniZe

display function

Recommended Posts

alieniZe    122
Hi guys, i studied alrdy the sound function, now im busy with the display function. I bought a book ( http://www.galileocomputing.de/katalog/buecher/titel/gp/titelID-1298), now i try to follow the book. But the display function part i dont understand. My main problems are the coordinates. How can i figure out the coordinats of it? ( Here the part http://www.galileocomputing.de/download/dateien/1171/galileocomputing_spieleprogrammierung.pdf). Here's my Code
void hintergrund() { dsply.Blt( 0, 0, hgrnd);}
		void abdeckung() { dsply.Blt( 60, 0, deckel);}
		void ziffer( int pos, int val) { dsply.Blt( 120+pos*20, 50, ziff[val]);}
		void feldstein( int z, int s) { dsply.Blt( 80+s*20, 100+z*20, fldst);}
		void fallstein( int z, int s, int offset) { dsply.Blt( 80+s*20, 100+z*20+offset, fllst);}
		void prevstein( int p, int z, int s, int b, int h){ dsply.Blt( 290+s*15+(4-b)*15/2, 410-p*70+z*15+(4-h)*15/2, prvst);}
		void update(){ dsply.UpdateBounds();}
I do not know how they expected to have the coordinates. Can someone help me? :/

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by alieniZe
Hi guys,

i studied alrdy the sound function, now im busy with the display function. I bought a book ( http://www.galileocomputing.de/katalog/buecher/titel/gp/titelID-1298), now i try to follow the book. But the display function part i dont understand. My main problems are the coordinates. How can i figure out the coordinats of it? ( Here the part http://www.galileocomputing.de/download/dateien/1171/galileocomputing_spieleprogrammierung.pdf).

Here's my Code


void hintergrund() { dsply.Blt( 0, 0, hgrnd);}
void abdeckung() { dsply.Blt( 60, 0, deckel);}
void ziffer( int pos, int val) { dsply.Blt( 120+pos*20, 50, ziff[val]);}
void feldstein( int z, int s) { dsply.Blt( 80+s*20, 100+z*20, fldst);}
void fallstein( int z, int s, int offset) { dsply.Blt( 80+s*20, 100+z*20+offset, fllst);}
void prevstein( int p, int z, int s, int b, int h){ dsply.Blt( 290+s*15+(4-b)*15/2, 410-p*70+z*15+(4-h)*15/2, prvst);}
void update(){ dsply.UpdateBounds();}


I do not know how they expected to have the coordinates. Can someone help me? :/
What coordinates? All those Blt() calls just offset by a constant plus the variable times a stride. What is your actual question?

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by alieniZe
I dont know how they come on this for example:

120+pos*20, 50....

or on this

290+s*15+(4-b)*15/2, 410-p*70+z*15+(4-h)*15/2

or this


80+s*20, 100+z*20+offset
Those numbers are presumably based on the size of the sprites used to draw. If the book doesn't say what the numbers are based on, the only person you're likely to get the answer from is the author.

Some are pretty obvious; 120+pos*20 for example will display the sprite 120px from the left edge of the screen, plus a further 20 for every pos units - again, that's presumably based on the size of the sprite (20px wide).

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Try drawing it out on a piece of paper. Working with this sort of code is rarely easy if you try to calculate it all in your head - looking at a picture of it will help you see the relationships between numbers.


hth
Jack

Share this post


Link to post
Share on other sites
alieniZe    122
thx for all ur answers, i wrote all on a paper and i still dont see how the calculate ist!

120+pos*20, 50....

or on this

290+s*15+(4-b)*15/2, 410-p*70+z*15+(4-h)*15/2

or this


80+s*20, 100+z*20+offset

or this

for( i = 0; i < 6; i++)
ultris_display.ziffer( i, i+1);

Share this post


Link to post
Share on other sites
remigius    1172

I looked trough the book, but I can't find any similar code in the first place. Anyway, as Steve said, they're basically just magic numbers used to draw various sprites at the correct offsets, specific to the sprites they're using and scene they want. For example, if you would want to draw 3 sprites like this:



So with 120px offset on the left and each sprite being 20x20px in size. Now you could draw each sprite manually like this:


dsply.Blt( 120, 0, sprite);
dsply.Blt( 140, 0, sprite);
dsply.Blt( 160, 0, sprite);


But when the size of the sprite should change, or if you want a different offset, you'd have to go and rewrite each and every line like this that draws the sprite. Instead, they chose to use a function to draw the sprites by some position number. Since you want 120px offset and the sprites are 20px wide, they used this function for the x coordinate, which will take some horizontal position (which is an arbitrary designation) and convert it to the correct X coordinate.


x = 120 + pos * 20


With this the first sprite in a row, at position 0, will be at x = 120 + 0 * 20, so at 120 pixels from the left. The same goes for subsequent sprites like 1 and 2, for which the function will return 140 and 160, and so on.

Obviously this is the most simple example in your code, but the rest of the functions are probably meant to do the exact same thing. Key to notice is that it all depends on the size of the sprites and at what offsets you want them to be drawn. These aren't some fixed rules in DirectX, but just some code you can set up yourself to make your work easier.

Hope this helps [smile]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this