Drawing Tiles, sorry for this Topic
Hi,
I have some problems with my Tiles drawing. I am using TANSTAAFL method ( Diagonal Iso ):
int tilex;
int tiley;
for(int y = 0; y < 10; y++)
{
for( int x = 0; x < 10; x++)
{
tilex = PosX+x*32-y*32;//x0,y0 is a reference point for the upperleft corner of tile (0,0)
tiley = PosY+y*16+x*16;
//use tilex and tiley to blit your tile
paint.DrawSurface( tilex , tiley, _RGB16BIT565( 255,0,255 ), lpDDSMapTiles[level->map[x][y].tile] );
}
}
But now how i can get smooth scrolling, this method draws all tiles
Thanx
Lutz Hören
psYchOtroW
tilex = PosX+x*32-y*32;
tiley = PosY+y*16+x*16;
Does this actually work? Even if it does, No! Slow! Use:
tilex = PosX + x << 5 - y << 5;
tiley = PosY + y << 4 + x << 4;
Faster! And as a rule (x % y) can be rewritten as (x & y-1)
To scroll, just increment or decrement PosX & PosY. I.e:
on left button { PosX-- }
on up button { PosY-- }
etc.
Oh, and happy Boxing Day!
tiley = PosY+y*16+x*16;
Does this actually work? Even if it does, No! Slow! Use:
tilex = PosX + x << 5 - y << 5;
tiley = PosY + y << 4 + x << 4;
Faster! And as a rule (x % y) can be rewritten as (x & y-1)
To scroll, just increment or decrement PosX & PosY. I.e:
on left button { PosX-- }
on up button { PosY-- }
etc.
Oh, and happy Boxing Day!
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
Ok, scrolling is no problem, but what can i do that he only draws the map that on the monitor ?
Thanx
Lutz Hören
Thanx
Lutz Hören
psYchOtroW
December 26, 2000 03:49 PM
quote: Original post by morfe
tilex = PosX+x*32-y*32;
tiley = PosY+y*16+x*16;
Does this actually work? Even if it does, No! Slow! Use:
tilex = PosX + x << 5 - y << 5;
tiley = PosY + y << 4 + x << 4;
Faster! And as a rule (x % y) can be rewritten as (x & y-1)
These optimizations are most likely done by the compiler already (almost guaranteed by any modern compiler). So, you won''t get any more speed out of using shifts instead of multiplies, but you will make the code slightly harder to follow. Might as well do what you mean (multiply by 32) and let the compiler worry about converting it.
<br>Morfe, another problem with your algorithm is logical: the C++ compiler will compute your algorithm as written in the wrong order. It will end up (as far as the compiler is concerned) looking like this:<br><br>tilex = (PosX + x) << ((5 - y) << 5);<br>tiley = (PosY + y) << ((4 + x) << 4);<br><br>or something to that effect. My point is that the compiler prioritizes binary operations as last. Though I know this point is mostly mute, I just want to clear this up in case anyone new to c++ or the algo is reading this...<img src="wink.gif" width=15 height=15 align=middle><br> <br><br> Brent Robinson<br>"Ich bin deinem Vatter!"
"The computer programmer is a creator of universes for which he alone is the lawgiver...No playwright, no stage director, no emperor, however powerful, has ever exercised such absolute athority to arrange a stage or a field of battle and to command such unswervingly dutiful actors or troops." - Joseph Weizenbaum-Brent Robinson
Ahem. Wrong:
Edited by - morfe on December 28, 2000 3:20:21 AM
@ not First (high) Unary operators* / div mod as Second Multiplicative and type casting operators and shl shr + - or xor Third Additive operators= <> < > Fourth (low) Relational, set membership, and type comparison operators<= >= in is
Edited by - morfe on December 28, 2000 3:20:21 AM
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
December 28, 2000 01:37 PM
Um, actually, according to all 3 books I have on C++ I am correct. Here is the Operator Precedence table from the book C++ for Dummies, 2nd Edition.
-quoted exactly as witten in said book
-quoted exactly as witten in said book
Highest Precedence
------------------
1.(), [], ->, . left to right
2.!, ~, +, -, ++,
--, &, *(cast),
sizeof right to left
3.*, /, % left to right
4.+, - " " "
5.<<, >> " " "
6.<, <=, >, >= " " "
7.==, != " " "
8.& " " "
9.^ " " "
10.| " " "
11.&& " " "
12.|| " " "
13.?: right to left
14.=, *=, /=, %=
+=, -=, &=, ^=
|=, <<=, >>= " " "
15., left to right
Um, sorry, that last post was me....
Brent Robinson
"Ich bin deinem Vatter!"
Brent Robinson
"Ich bin deinem Vatter!"
"The computer programmer is a creator of universes for which he alone is the lawgiver...No playwright, no stage director, no emperor, however powerful, has ever exercised such absolute athority to arrange a stage or a field of battle and to command such unswervingly dutiful actors or troops." - Joseph Weizenbaum-Brent Robinson
First, even if your order of precendence is correct, you still groupd the equations wrong. It should be :
tilex = PosX + (x << 5) - (y << 5);
tiley = PosY + (y << 4) + (x << 4);
Second, different compilers probably use different precedences. So we''re probably both right.
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..."
"When you are willing to do that which others are ashamed to do, therein lies an advantage."
tilex = PosX + (x << 5) - (y << 5);
tiley = PosY + (y << 4) + (x << 4);
Second, different compilers probably use different precedences. So we''re probably both right.
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..."
"When you are willing to do that which others are ashamed to do, therein lies an advantage."
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
That algo I posted was supposed to illustrate the way the compiler would organize the operations, not the way the actual algo should look. And your right about different compilers using different procedures, as almost no one actually follows the C++ standard EXACTLY, but that table is correct as far as the standard is concerned.
Brent Robinson
"Ich bin deinem Vatter!"
Brent Robinson
"Ich bin deinem Vatter!"
"The computer programmer is a creator of universes for which he alone is the lawgiver...No playwright, no stage director, no emperor, however powerful, has ever exercised such absolute athority to arrange a stage or a field of battle and to command such unswervingly dutiful actors or troops." - Joseph Weizenbaum-Brent Robinson
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement