Welcome! Log In Create A New Profile

Advanced

Detecting of pressing button on sprite

Posted by iSubaru 
Detecting of pressing button on sprite
September 28, 2014 02:28PM
Hello

I have been searching Regular Net as well as Under-Net for this info and couldn't find it, maybe because of Nintendo DS coding habbits I asked wrong phrase, anyway here is the thing I would like to achieve...
I would like to have in code something like this:
"If Wii Cursor is pointing at Sprite and A Button is pressed then [...]"
I load the sprites so far with GRRLIB_DrawTile for the purpose of having the tileset (frames).
I hope it's possible here as it was on DS :)

Thank you in advance and have a nice day :)

iSubaru
Re: Detecting of pressing button on sprite
September 29, 2014 11:52AM
Hello

I guess I wasn't clear enough on that one...
I will give the example from MLLib, it was like this:
if (ML_IsWiimoteInSprite(0, &reset) && (Wiimote[0].Newpress.A))
It goes like this:
"If Wiimote cursor is pointing at named sprite and A Button will be pressed, do [...]"
I would like to achieve something like that without using MLLib anymore (compatibility reasons).

Thank you in advance and have a nice day :)

iSubaru
Re: Detecting of pressing button on sprite
October 01, 2014 01:48AM
You will have to do it the hard way. You have to store the coordinates of your sprites and then check all of them against the coordinates of the IR pointer when a button is pressed.

You will basically have to make your own version of ML_IsWiimoteInSprite() since GRRLIB is not keeping track of all your sprites (you have to know where they all are on the screen)

I am assuming know how to detect the button press events and how to know where the pointer is on the screen.
Re: Detecting of pressing button on sprite
October 01, 2014 10:51PM
Thank gods the sprites in this project won't be moving an inch from the starting position...

Hmm correct me if I'm wrong, if I get this correctly then:
- I have to "write down" positions of the sprites X and Y (aka from X1 to X2 and Y1 to Y2).
- When Wiimote points in the are of interest and button is pressed, then "TRUE"
- So for example "if Wiimote points somewhere between x>48 and x<96 and y>48 and y<96 AND A_Button is pressed, do the coffee" thing...

If so then hoo boy that will be time consuming xD
Maybe I can get a detailed look into DS libraries with something similar of sprite pressing and rewrite it for Wii, of course with GRRLib commands...maybe...

Quote

I am assuming know how to detect the button press events and how to know where the pointer is on the screen.
The button detections seems to be working just fine (Home button FTW), however for now I wasn't able to make cursor appear on the screen and follow the x,y positioning, I will try the more basic example of drawing white square instead of using the image for now
Re: Detecting of pressing button on sprite
October 02, 2014 01:52AM
I usually maintain a list of the sprite in an array or structure that I can loop through.


#define SPRITESHEET_MAX 30
#define GROUP_MAX 10

//============================================================================

typedef struct {
	GRRLIB_texImg *sprite;  

	bool is_loaded;

	float x, y; 

} SpriteSheetStruct;

SpriteSheetStruct ssl[SPRITESHEET_MAX]; //spritesheet_list

GRRLIB_texImg * spritesheet_get_pointer( int ind ){
	if(ind > SPRITESHEET_MAX-1) return NULL;
	if(!ssl[ind].is_loaded) return NULL;
	
	return ssl[ind].sprite;	
}

void spritesheet_load( int ind, const char *fileName, int width, int height, int start, int stop ){  //load a sprite sheet
	
	if(ind > SPRITESHEET_MAX-1) return;
	
	engine_print( "Loading SpriteFile; " );
	engine_print(fileName );	

	ssl[ind].sprite=GRRLIB_LoadTextureFromFile(fileName);

	if( ssl[ind].sprite!=NULL ) GRRLIB_InitTileSet( ssl[ind].sprite, width, height, start );

	ssl[ind].is_loaded=( ssl[ind].sprite!=NULL );
	
	if( !ssl[ind].is_loaded ) { engine_println( "...error!" ); return; } //error
	
	engine_println( "...done." );
	
}

void spritesheet_free(int ind){  //free memory
	if(ind > SPRITESHEET_MAX-1) return;
	if( ssl[ind].is_loaded ) GRRLIB_FreeTexture(ssl[ind].sprite);  
}

void spritesheet_free_all(){ //free memory
	int i;	
	for( i=0;i
 
 
 then I use the functions like so;
 
 	spritesheet_load( S_DIALOGBOX,  "image/dialogbox.png",  640, 480, 0, 1 );
 	spritesheet_midhandle( S_DIALOGBOX, TRUE );
 
 
 	GRRLIB_DrawImg( screen_center_x, screen_center_y, spritesheet_get_pointer(S_DIALOGBOX), 0, 1, 1, background_col[enemy_col_index] );
 
 
so when you are doing the check for the button press you just use a loop;
 int i;	
 	for( i=0;i<SPRITESHEET_MAX;i++) {
 if(
 	ssl.x > pointer_x &
	ssl.y > pointer_y & & & & blah blah ) {
//do something
}

}




Edited 1 time(s). Last edit at 10/02/2014 02:05AM by owen.
Sorry, only registered users may post in this forum.

Click here to login