|
Can't get my buffer to work |
gamelord12
Member #8,586
May 2007
|
http://rafb.net/p/vYtDlk13.html I'm trying to make a sword fighting game. Most of it is commented out because I don't have the sprites for it and I want to know that the most basic parts work first. For some reason, my sprites either aren't being grabbed off the sprite sheet or they're just not showing up on screen. I get a white background after the title screen like I'm supposed to but then the stick figure fighting stance that's supposed to display doesn't show up. |
CGamesPlay
Member #2,559
July 2002
|
(Reposted here because rafb expires)
This line is wrong:blit(fightStances[frame1], buffer, p1, staticy, p1, staticy, fightStances[frame1]->w, fightStances[frame1]->h); Also, instead of doing this to display your title screen, which uses 100% CPU: while(!key[KEY_SPACE]) { blit(SwordPlayTitle, screen, 0, 0, 0, 0, SwordPlayTitle->w, SwordPlayTitle->h); textprintf_centre_ex(SwordPlayTitle, font, SCREEN_W / 2, 460, makecol(255, 255, 255), -1, "Press Space Bar to Continue..."); } destroy_bitmap(SwordPlayTitle); rest(50); Do this instead: blit(SwordPlayTitle, screen, 0, 0, 0, 0, SwordPlayTitle->w, SwordPlayTitle->h); textprintf_centre_ex(SwordPlayTitle, font, SCREEN_W / 2, 460, makecol(255, 255, 255), -1, "Press A Key to Continue..."); destroy_bitmap(SwordPlayTitle); readkey();
-- Ryan Patterson - <http://cgamesplay.com/> |
gamelord12
Member #8,586
May 2007
|
Could you explain why there should be zeroes there? Why is it that my original way uses 100% CPU, and what other tricks could you tell me to stop me from running into similar problems or poor practice down the road? How do you post your code on this forum like that? Thanks. |
CGamesPlay
Member #2,559
July 2002
|
Quote: Could you explain why there should be zeroes there? Those are the "source x" and "source y" points of the bitmap. If you have your sprite image and you set them to 32, 32, the first 32 pixels on the top and left will be skipped, because you said to start copying from the pixel at 32, 32. Quote: Why is it that my original way uses 100% CPU Well, if you read it, he code sees if escape is pressed, draws the image to the screen, draws the text to the screen, sees if escape is pressed, draws the image to the screen... It's always doing something. My way draws the image to the screen, draws the text to the screen, then waits for a key to be pressed. Quote: what other tricks could you tell me to stop me from running into similar problems or poor practice down the road? Just ask questions on the forums about what you aren't sure about. Quote: How do you post your code on this forum like that? Thanks. This link is the "Help" button above the post reply box. -- Ryan Patterson - <http://cgamesplay.com/> |
gamelord12
Member #8,586
May 2007
|
Thanks for the help so far, but I'm still having issues. My current problems are: 1. Stamina bars do not display at all On another note, could someone take a look at my timer when used for my framerate? I'm trying to get it so that I can easily adjust and increase the flow of the animation. Is there an easier/more efficient way or any tweaks that could be done to the code? Here's my sprite sheet. Keep in mind that in actuality, the sheet will be 240x960. |
CGamesPlay
Member #2,559
July 2002
|
Quote: 1. Stamina bars do not display at all Why would they? You never call the function that draws them. Quote: 2. Only one frame of the stick figure displays, and it constantly has a black box written over top of it because it isn't reading in the other three frames of the animation. Sure. You call grabframe and pass 1 as the number of columns, but that image has 4. Quote: 3. Is there a way to specify what color is read as transparent? In class, we did a sample program with a cat going across the screen and pink was the transparent color...I'm not sure if that's the default or the only transparent color. Nope, sorry. Also, this part is wrong: for(int x = 0; x <= 3; x++) { fightStances[x] = grabframe(temp, 240, 240, 0, 0, 1, x); } fightStances is BITMAP* fightStances[3]. That means that you have 3 indexes to work with: 0, 1, and 2. But your loop writes to 0, 1, 2, and 3. That's one too many. Change the "x <= 3" to "x < 3", so you will only write to 0, 1, and 2. -- Ryan Patterson - <http://cgamesplay.com/> |
gamelord12
Member #8,586
May 2007
|
Those were such obvious answers. Thank you, I can't believe I missed them. However, as far as the columns are concerned, I copied the code for the grabframe() function right out of a tutorial program, and they actually read columns from the other direction. I'm pretty sure I copied that right when I applied it to this program, though it may have been after I pasted it up on this board. I'll post a newer version when my next inevitable problem turns up. As for my timers, are they okay? Or is there a better way to do it? |
LennyLen
Member #5,313
December 2004
|
Quote: However, as far as the columns are concerned, I copied the code for the grabframe() function right out of a tutorial program, and they actually read columns from the other direction. The number of columns is the same, no matter what direction you look at them from.
|
CGamesPlay
Member #2,559
July 2002
|
Unless you took them from top to bottom, in which case they are called "rows". But the code shows that they run form left to right. -- Ryan Patterson - <http://cgamesplay.com/> |
gamelord12
Member #8,586
May 2007
|
Okay, so my updated code:
My sprite animates, but depending on the speed, it will only run through for a few cycles. Like I said before, I feel like I'm going through that loop REALLY ineffieciently. How can I make it easy to adjust the animation speed? |
CGamesPlay
Member #2,559
July 2002
|
Well, you should have your game loop looking something like this:
-- Ryan Patterson - <http://cgamesplay.com/> |
LennyLen
Member #5,313
December 2004
|
Quote:
currentFrame = 0; if(currentFrame >= 3) currentFrame = 0;
Why are you checking if currentFrame is greater than or equal to 3 when you've just set it to 0?
|
CGamesPlay
Member #2,559
July 2002
|
Whoops, fixed, thanks. -- Ryan Patterson - <http://cgamesplay.com/> |
gamelord12
Member #8,586
May 2007
|
CGames, I did like some of what I saw in your program, but there was a lot that seemed either unnecessary or I just didn't understand it. Here's my updated program (issues listed in first comment lines):
|
zavirax
Member #8,634
May 2007
|
forgive me if im wrong i only had a quick skim over it... i cant see that you have declared width and height but i think you must have becaus eyou would be having erors...hmmm...well check it and im probably wrong.::) |
gamelord12
Member #8,586
May 2007
|
Yes, everything that needs to be declared is declared, however, my stick figure guy now moves very much like a robot. The frame that it displays appears to be random, and it only plays like 1 every second. What's wrong? |
Onewing
Member #6,152
August 2005
|
Quote: if(ticks == (100 % frameRate)) This seems...odd to me. Maybe I don't understand your logic, but what I get is ticks is being changed by a hardware interrupt, meaning it could go right past (100 % frameRate) before the if statement is called. ------------ |
gamelord12
Member #8,586
May 2007
|
yeah, I changed it to this soon after posting:
Then after I did that, I noticed I had to switch the 100 and frameRate, and it works. Thanks guys! Now the next possible problem that could come up would be during my animations that run when buttons are pressed. I'll let you know how that works out, but maybe in another topic. |
|