Sign in to follow this  
shanelaffond13

Allegro and sprite sheets

Recommended Posts

Hi. My name is Shane and I am using Allegro to load a sprite sheet of 288 X 608. I am having trouble looping through the loading process. Here is my code: for( n = 0; n < 172; n++ ) { if( n == 9 || n == 18 || n == 27 || n == 36 || n == 45 || n == 54 || n == 63 || n == 72 || n == 81 || n == 90 || n == 99 || n == 108 || n == 117 || n == 126 || n == 135 || n == 144 || n == 153 || n == 162 || n == 171) y += 32; while(n < 172) { ground[n] = create_sub_bitmap( grnd, x, y, 32,32 ); } } Please help me. I don't know how to loop through this.

Share this post


Link to post
Share on other sites
That's some nasty brute force code. I'd do it more like this:


for( int n = 0; n < 172; n++ )
ground[n] = create_sub_bitmap(grnd, (n % 9) * 32, (n / 9) * 32, 32, 32);


Also, when you solve your own problem it would be good if you explained your solution. Someone else might be having a similar problem or might just be curious to see your solution.

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