After I finally got my ass up and began SDL learning, I made my first program. The whole thing is a rectangle based shooter, similar to my Blitz "Prick Fight".
The problem is, when I move a rectangle off screen, it permanently removes the portion that I moved off the screen. I do not yet know weather it actually modifies my width and height or if it stops drawing half the rectangle, but has anyone had a similar problem? If so, do you know what is wrong? Is my best bet just making a boundary 5 or so pixels from the edge of the screen to prevent peeps from leaving it? If so, what about bullets, which are also rectangles? That would look gay if they just disappear near the edge of the screen…
I'll do some fprintf's and tell you if it actually changes my x,y,w and h.
If it does change the size, I can just update it when the player re-enter's the screen, but that would make it a hassle to change the player size....
As I currently have it, the player does not have his own X and Y. The player class has a public SDL_Rect object inside it, which has X,Y,W,H as members. Do you think I should make the players have private X,Y,W,H and every time the rectangle's X,Y,W, and H are not equal to them, set them equal?
And, to make these new private members, should I just privately inherit the SDL_Rect class and add some accessors?
As I am sure you can all tell, I am not only new to SDL but also to C++ as a whole, so forgive my many questions. For anyone who actually replies, thanks a bunch. :D
Rectangle problem with leaving screen (SDL)
Moderator: Coders of Rage
Woah...check this out.
1) Make it so you don't go off screen
2) Make my player class have X,Y,W,H and set the rect X,Y,W, and H equal to them if they are not already.
If someone has a better idea, I am open minded.
Oh, and DJ Yoshi, if you even think about coming in here and dicing my SDL skillz that I gained yesterday, I'll wedge my foot so far up your asshole that you'll never shit again. Oh, yeah, and I'll delete your post. :spin:
However, if you post relevant to the topic, then thanks for posting. :D
That's weird...I think every frame that the x is negative, it'll add my negative value to my width...oh well. We now know it actually changes the size. I guess I will do two things.My output data wrote:X: 1
Y: 10
W: 32
H: 64
X: -2
Y: 10
W: 32
H: 64
X: -3
Y: 10
W: 30
H: 64
X: -3
Y: 10
W: 27
H: 64
X: -3
Y: 10
W: 24
H: 64
X: -3
Y: 10
W: 21
H: 64
1) Make it so you don't go off screen
2) Make my player class have X,Y,W,H and set the rect X,Y,W, and H equal to them if they are not already.
If someone has a better idea, I am open minded.
Oh, and DJ Yoshi, if you even think about coming in here and dicing my SDL skillz that I gained yesterday, I'll wedge my foot so far up your asshole that you'll never shit again. Oh, yeah, and I'll delete your post. :spin:
However, if you post relevant to the topic, then thanks for posting. :D
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
Your best bet is to make your own classes that contain the x and y values. When it comes time to draw the rectangle, those values associated with the rect class should be set to yours. Don't worry about checking if they are set... just do it. The values in the rect class are actually only supposed to be temporary.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
What in the hell? I hope I'm understanding this right.Arce wrote:But if I don't check if they are equal and I just set them to eachother every frame, won't that slow the program down? We must remember that I am on an antique...x.x
Mar, I'll try that in a few and post the results.
You're telling me that you're checking if two values equal one another, and if they don't you're setting them equal to each other?
Dear god, that is much slower. You realize that by the time the logic is done to see if they are equal, you've wasted about (if not more) time and power than just setting them equal? Then, if they aren't equal, you set them equal.
At best your method will be as fast as JSL's (assuming evaluating conditions requires about the same amount of work as setting a variable, which I doubt), and potentially it can run 1/2 the speed it would because you'd also be setting the variable equal to another ontop of the normal check.
Aight.What in the hell? I hope I'm understanding this right.
You're telling me that you're checking if two values equal one another, and if they don't you're setting them equal to each other?
Dear god, that is much slower. You realize that by the time the logic is done to see if they are equal, you've wasted about (if not more) time and power than just setting them equal? Then, if they aren't equal, you set them equal.
At best your method will be as fast as JSL's (assuming evaluating conditions requires about the same amount of work as setting a variable, which I doubt), and potentially it can run 1/2 the speed it would because you'd also be setting the variable equal to another ontop of the normal check.
Hey, get this. I set the width and height every frame to the player's new width and height, and now it won't let me leave the screen. Every frame it pushes me back. I guess SDL cannot draw offscreen, so prevents from doing so by making the rectangle smaller. Now that I make it bigger after it makes it smaller, it just pushes me back on. o.o
Anyway, I'll get to that button Mar.
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON