|
Is there a reason why this code will not display the bitmaps correctly? |
Matt Kindy
Member #7,331
June 2006
|
I typed up this code and changed some stuff, but now the animation isn't showing. In this, I have a 1280 * 1024 bitmap that I basically use as the buffer(white_screen), and a bunch of animation code. For some reason, instead of the animation showing up after the whole screen turns white, I get a small white square in the upper right corner(about 100 * 100 large). Can anybody help me with this? Thanks!
|
Jonny Cook
Member #4,055
November 2003
|
Yes, there most certainly is a reason. And it's probably because you're doing it all wrong! You shouldn't mix your drawing code with your logic code like that. Very slow. I don't think I can tell you how to fix your code, because I honestly don't understand what it's suppose to accomplish. However, I can show you what your should look like.
That's basically what you game should consist of. By no means does it have to look exactly like that (I'm sure if you are using threads it will be significantly different), but that should give you a general idea of what is right. Once you structure your code better, finding bugs will be a lot easier. Then, when you come here asking for help, people might actually be able to help you. I also suggest you read the Allegro manual. It might help you understand timing and drawing a little better. Reading the source to a simple game might also help. Check out the open source games in the Depot. The face of a child can say it all, especially the mouth part of the face. |
Matt Kindy
Member #7,331
June 2006
|
Jonny Cook said: ...I honestly don't understand what it's suppose to accomplish How can you not?? It's only simple C with some allegro drawing elements! It was working fine but then I changed some stuff and now it's not. First I load the bmps. Then I draw them to the buffer, blitting the buffer to the screen each time I do that, and clearing the buffer in between(achieving the 'motion'!). Then, once the Fallen monster gets 'hit' (frame 6), the Fallen starts to die. If you press the arrow keys, the animation moves up, down, left, or right. When you press enter, it re-centers. If you hold ESC, it quits. Any other questions? |
Jonny Cook
Member #4,055
November 2003
|
Well, I'm sorry if I missed all the signs. To me, it looks like a big mess of rest, blits, clears, and perhaps a few comments that only point out the obvious. It's not well formed code. Yes, I admit that I didn't spend a considerable amount of time decrypting it, but to me it's quite obvious why it won't run properly. And thank you for ignoring the big block of text which points out some of the major flaws of your code. The face of a child can say it all, especially the mouth part of the face. |
Matt Kindy
Member #7,331
June 2006
|
I admit that I forgot the destroy_bitmaps()... I should've caught that., but there's no reason to pick apart my code when you imply that you don't even know what it means. I just want someone to analyze this code for me to see if they maybe notice something wrong that I missed. In your case, you did spot the destroy_bitmaps, so I thank you. I will improve my code, but I've been doing so much trying to get this done for one of my classes, that I haven't been able to refine it. I understand why not to use rest. It is a quick solution, albeit not a good one. I just do not have the time right now to learn timers. EDIT: I did have a bunch of destroy_bitmap()s in my 'destroybitmap()' function. So I had destroyed almost everything... but not the fal sprite array.
|
ReyBrujo
Moderator
January 2001
|
One quick note: char fal_bmp_name[10]; /* ... */ for(i=0; i < 16; i++){ sprintf(bar_bmp_name,"bar20%d.bmp", i); "bar2011.bmp" has 11 characters (plus '\0'), so your arrays should be 12 at least, not 10. -- |
Matt Kindy
Member #7,331
June 2006
|
Oh, thanks Rey! That was one of the things I changed... I only had 9 frames at first, so it was alright.Then I changed it to 16 so i would've needed 11 EDIT: Could be not loading because the images are set to 16 million. Hold on , let me check... EDIT[2]: Yes! The bar images were set to 16 million color mode. But, sadly: NO! It still doesn't work... and I changed: white_screen = create_bitmap(1280,1024); |
Jonny Cook
Member #4,055
November 2003
|
I was not aware that you are on a time schedule, but nonetheless. What I was getting at in my earlier posts is that it would take less time to do it right, even if initially there is a little bit of extra learning to do. Setting up a timer takes about 8 lines of code and it can be summed up in 30 seconds. Based on what information you gave us about your problem, it's hard to tell what's wrong. The quality of your code makes it even harder. One of the many reason people separate their logic code from their drawing code is it makes it easier to debug. Such a simple program, if coded correctly, would take very little time to both create and debug. Also, checking the return values from the create and load bitmaps functions is always a good idea. And perhaps you could tell us the last major change you made to your code before it stopped working.
That's the standard Allegro timer implementation. The face of a child can say it all, especially the mouth part of the face. |
Matt Kindy
Member #7,331
June 2006
|
Quote: I don't understand this here... so, you're in a loop.if user presses escape, it will exit after ALL the logic is done(when logic_counter <= 0). What purpose does the logic_counter serve, outside of that? You have the variable also continually going up( at least, that's what I assume)... so the only thing I can make out would be that.. it would be going up at a constant rate and once enough things were finished in the loop, the --logic_counter would overcome(loop finishing cycles more quickly) the ++ and you would quit the logic loop, possibly even before you were intending. Are my conclusions correct(most likely not)? Could you explain why they are false? and what your code really means. |
ReyBrujo
Moderator
January 2001
|
Remember that your timer is executed every 1/60 seconds (in example). So, the logic_counter variable will be incremented around 60 times per second. Your logic can be extremely fast (say, it can be executed in 1/100 seconds), but since the counter increases only 1/60, your logic will be executed 60 times per second (and thus, you will draw on the screen only 60 times per second). If your logic is too heavy (say, it executes in 1/30 seconds), your timer variable will begin increasing. If this happens, you can stop the execution of the program. My implementation is a bit different: while (! quit) { while (logic_counter < timer_counter) { do_logic(); logic_counter++; } do_input(); do_output(); } where timer_counter is the variable that is being incremented by the timer, and do_input is the function that sets the quit flag if necessary. -- |
Jonny Cook
Member #4,055
November 2003
|
The code sets a function (inc_logic_counter) to be called 60 times a second (BPS_TO_TIMER(60)). Each time the function is called, a counter gets incremented. The counter gets incremented 60 times a second. The logic only runs if the counter is greater than 0 (if (logic_counter > 0) {). Since the counter only gets incremented every 60th of a second, the logic will run no more than 60 times a second. Using this method, on slower computers the graphics might get a little laggy, but you will never miss a logic frame, and it will never go too fast. The face of a child can say it all, especially the mouth part of the face. |
Matt Kindy
Member #7,331
June 2006
|
GODDAMN!!!! I found it!!!... it was, of course, not in the code I gave you. I didn't change my array to size 16 from 9.. so ya... now it works. thanks. keep explaining timers please! EDIT: BTW I am also very inexperienced in Allegro.:-[ |
ReyBrujo
Moderator
January 2001
|
We all have been/still are, don't worry -- |
Matt Kindy
Member #7,331
June 2006
|
Could you also explain how to create basically a map that you can scroll through? EDIT: BUT TIMERS ARE MORE IMPORTANT!!! EDIT: I'm gonna make a new thread called 'I don't get timers...!' post there, ok?. |
|