Page 1 of 2

2 Questions on SDL...

Posted: Tue Mar 10, 2009 8:26 pm
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?

Re: 2 Questions on SDL...

Posted: Tue Mar 10, 2009 8:29 pm
by wtetzner
Instead of using events, use the keystate array in your main loop.
http://www.lazyfoo.net/SDL_tutorials/lesson10/index.php

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 12:40 pm
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.

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 2:53 pm
by MarauderIIC

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 5:58 pm
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();
}

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 6:24 pm
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

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 6:33 pm
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?!?

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 6:59 pm
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
      }
   }
}

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 7:03 pm
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

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 7:11 pm
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. :)

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 7:15 pm
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... =(

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 7:29 pm
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.

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 8:24 pm
by ibly31
Hmm, now text isn't working: is there a way to draw text without the sdl_ttf extention?

Re: 2 Questions on SDL...

Posted: Wed Mar 11, 2009 11:16 pm
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();
} 

Re: 2 Questions on SDL...

Posted: Thu Mar 12, 2009 6:37 pm
by ibly31
What size sprites is the ES team using? I'm using 32x32 is that the way to go?