Public Group

# Introduction and a question to boot.

This topic is 3821 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm new to the forums themselves, but I have been using GD as a resource for a while. A little about myself: I've been playing games since I was a kid. Now I'm about to start computer science at uni and my passion for games hasn't gone away. That's why I'm here :) Now, let's get to business :P I'm using allegro for now to familiarise myself with timers, blitting etc. but one thing has been annoying me. all the blitting functions only take int values which makes it pretty restrictive as to what values you are allowed to use. For example, you can't make the speed of an object .5 or even divide anythinge too because you'll end up with decimals. I was thinking of writing a rounding function but I bet that's the completely wrong way of doing things. Col.

##### Share on other sites
Rounding is a bad idea. Firstly it won't accomplish what you think it would accomplish. Secondly the coordinate plane that makes up your screen is integer where the upper left corner is (0,0). That is why the blit routines don't take a decimal value. To accomplish your speed your best bet is to use a vector because not only does it contain the speed of the sprite but it also contains the direction in which the sprite is moving. Yes vectors do allow for decimal values be it float or double. Since I assume you are using C++ because of allegro you can obtain the vector type by using #include<vector> I wish I could give you a example of it in use but I moved away from C++ when C# and MDX came out. Now that MDX is gone I am using C# and XNA.

##### Share on other sites
I have made a vector struct for that purpose but when I try to use its members in the blitting function it still passes the float value while it needs an int.

void blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);

##### Share on other sites
It's been (wow) almost 3 years since I touched C++ and my retention sucks horribly but I believe you should be looking into casts to get that float to turn into an int. Or, you could just do away with the precision (do you really need it for your movement?) and create a vector of integers so the types match.

##### Share on other sites
Thanks, that works perfectly :)

I'm sure i'll be back with some more trivial questions in the near future.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013743
×