2 Questions on SDL...

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

2 Questions on SDL...

Post by ibly31 »

One: How do you change the cursor from that odd inverted black one that it makes you have?

Two: How do you get keys to repeat? My keys are like... semiautomatic, one event per press, instead of auto, one press, as many events as you want until you let go. Hold down any key while in a text box, you see how it goes ssssssssssssssssssss? Instead of just s? How do you do this in SDL?
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
wtetzner
Chaos Rift Regular
Chaos Rift Regular
Posts: 159
Joined: Wed Feb 18, 2009 6:43 pm
Current Project: waterbear, GBA game + editor
Favorite Gaming Platforms: Game Boy Advance
Programming Language of Choice: OCaml
Location: TX
Contact:

Re: 2 Questions on SDL...

Post by wtetzner »

Instead of using events, use the keystate array in your main loop.
http://www.lazyfoo.net/SDL_tutorials/lesson10/index.php
The novice realizes that the difference between code and data is trivial. The expert realizes that all code is data. And the true master realizes that all data is code.
User avatar
programmerinprogress
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Wed Oct 29, 2008 7:31 am
Current Project: some crazy stuff, i'll tell soon :-)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++!
Location: The UK
Contact:

Re: 2 Questions on SDL...

Post by programmerinprogress »

ibly31 wrote:One: How do you change the cursor from that odd inverted black one that it makes you have?
You could track the cursor, and then blit your own cursor image to the cursor location (and hide the actual cursor).

I do that a lot when i'm trying out new features with editors.
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D

I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: 2 Questions on SDL...

Post by MarauderIIC »

I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: 2 Questions on SDL...

Post by ibly31 »

So, how do I know which key is which in the array? Is there a specific list?

So if I'm checking for up, and its 3rd in the list, would i do *psuedo code*

if(keystatearray[3] == 1){
movecharacterup();
}
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
Kros
Chaos Rift Regular
Chaos Rift Regular
Posts: 136
Joined: Tue Feb 24, 2009 4:01 pm
Current Project: N/A
Favorite Gaming Platforms: PC, Playstation/2/3
Programming Language of Choice: C++
Location: Oregon,USA
Contact:

Re: 2 Questions on SDL...

Post by Kros »

I highly recommend looking through this page:

http://www.libsdl.org/cgi/docwiki.cgi/SDL_API

And to specifically answer your second question:

http://www.libsdl.org/cgi/docwiki.cgi/S ... eKeyRepeat
Isaac Asimov wrote:Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest.
YouTube Channel
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: 2 Questions on SDL...

Post by ibly31 »

RANDOMERRORWTF?!?!?!

Okay... this is really f***ing gay.

THIS code works:

Code: Select all

void initClips(){
	
	for(int y = 0; y <=11; y++){
		for(int x = 0; x <= 3; x++){
			clip[x*y].h = 32;
			clip[x*y].w = 32;
			clip[x*y].x = x*32;
			clip[x*y].y = y*32;
			
		}
	}
} 
But this doesn't:

Code: Select all

void initClips(){
	int val = 0;
	for(int y = 0; y <=11; y++){
		for(int x = 0; x <= 3; x++){
			clip[val].h = 32;
			clip[val].w = 32;
			clip[val].x = x*32;
			clip[val].y = y*32;
			val++;
		}
	}
} 
I did this, because I realized that it would do (0*0,0*1,0*2,0*3,1*0,1*1,1*2,1*3,etc...), instead of what I wanted, just a straight value that increments. Really, wtf is wrong with this?!?
Last edited by ibly31 on Wed Mar 11, 2009 7:06 pm, edited 1 time in total.
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: 2 Questions on SDL...

Post by M_D_K »

Code: Select all

void initClips(){
   int val = 0;
   for(int y = 0; y <=11; y++){
      for(int x = 0; x <= 3; x++){
         clip[val].h = 32;
         clip[val].w = 32;
         clip[val].x = x*32;
         clip[val].y = y*32;
         val++; //try this
      }
   }
}
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: 2 Questions on SDL...

Post by ibly31 »

OH sorry, um, Damn, I actually was testing around, to see if it would work with "val = val + 1" instead of "val++" and I didn't want you guys bitching at me, so I change it to val++, and i forgot the val =... and thats not the error. I dont under-effin-stand! x*y are both ints... and val is an int too
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
Kros
Chaos Rift Regular
Chaos Rift Regular
Posts: 136
Joined: Tue Feb 24, 2009 4:01 pm
Current Project: N/A
Favorite Gaming Platforms: PC, Playstation/2/3
Programming Language of Choice: C++
Location: Oregon,USA
Contact:

Re: 2 Questions on SDL...

Post by Kros »

ibly31 wrote:OH sorry, um, Damn, I actually was testing around, to see if it would work with "val = val + 1" instead of "val++" and I didn't want you guys bitching at me, so I change it to val++, and i forgot the val =... and thats not the error. I dont under-effin-stand! x*y are both ints... and val is an int too
Setup some breakpoints and run through it a few times. The debugger is there for a reason. :)
Isaac Asimov wrote:Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest.
YouTube Channel
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: 2 Questions on SDL...

Post by ibly31 »

Oh duh... I made it SDL_Rect clip[41] and it was trying to write 44 elements. Sorry, lol even sorry-er to my heart, my blood pressure was like *2. :oops:

EDIT:
Kros wrote:
ibly31 wrote:OH sorry, um, Damn, I actually was testing around, to see if it would work with "val = val + 1" instead of "val++" and I didn't want you guys bitching at me, so I change it to val++, and i forgot the val =... and thats not the error. I dont under-effin-stand! x*y are both ints... and val is an int too
Setup some breakpoints and run through it a few times. The debugger is there for a reason. :)
I'm fullscreening the window, so it errors if I try to debug... =(
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
Kros
Chaos Rift Regular
Chaos Rift Regular
Posts: 136
Joined: Tue Feb 24, 2009 4:01 pm
Current Project: N/A
Favorite Gaming Platforms: PC, Playstation/2/3
Programming Language of Choice: C++
Location: Oregon,USA
Contact:

Re: 2 Questions on SDL...

Post by Kros »

ibly31 wrote:I'm fullscreening the window, so it errors if I try to debug... =(
You can remove the fullscreen option for debugging purposes.

Anyway, glad you figured it out.
Isaac Asimov wrote:Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest.
YouTube Channel
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: 2 Questions on SDL...

Post by ibly31 »

Hmm, now text isn't working: is there a way to draw text without the sdl_ttf extention?
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
wtetzner
Chaos Rift Regular
Chaos Rift Regular
Posts: 159
Joined: Wed Feb 18, 2009 6:43 pm
Current Project: waterbear, GBA game + editor
Favorite Gaming Platforms: Game Boy Advance
Programming Language of Choice: OCaml
Location: TX
Contact:

Re: 2 Questions on SDL...

Post by wtetzner »

ibly31 wrote:So, how do I know which key is which in the array? Is there a specific list?

So if I'm checking for up, and its 3rd in the list, would i do *psuedo code*

if(keystatearray[3] == 1){
movecharacterup();
}
It's basically an array of booleans. And you can use the SDL constants. For example, for the up key:

Code: Select all

if(keystates[SDLK_UP]){
     movecharacterup();
} 
The novice realizes that the difference between code and data is trivial. The expert realizes that all code is data. And the true master realizes that all data is code.
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: 2 Questions on SDL...

Post by ibly31 »

What size sprites is the ES team using? I'm using 32x32 is that the way to go?
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
Post Reply