Page 1 of 1

GetCurrent??

Posted: Fri Nov 26, 2010 12:21 am
by MadPumpkin
How might I go about a "GetCurrent" function. Basically I want the node you click on, to be selected. Then from there I can delete the current one from the vector or move it.

Re: GetCurrent??

Posted: Fri Nov 26, 2010 3:59 am
by adikid89
Am I the only one who doesn't understand your question? The std::vector class has these functionalities... so you can easily use that.

Re: GetCurrent??

Posted: Fri Nov 26, 2010 9:23 am
by N64vSNES
I'm not positive I understood your question, I'm going to assume you are using C++.

________
|Node 1| -------------> if ( Clicked == true ) { Current == 1; }
|__ ___|

________
|Node 2|-------------> if ( Clicked == true ) { Current == 2; }
|__ ___|

________
|Node 3|-------------> if ( Clicked == true ) { Current == 3; }
|__ ___|

Code: Select all

int GetCurrent() {	
	return Current;
}

void EraseCurrent() {
	Nodes.erase(Nodes.begin() + GetCurrent()); // Nodes being the vector
}
etc...
I think thats what you mean?

Re: GetCurrent??

Posted: Fri Nov 26, 2010 2:17 pm
by dandymcgee
No idea what you're trying to ask. If you could reword your question it would help us help you.

Re: GetCurrent??

Posted: Sun Nov 28, 2010 4:10 pm
by MadPumpkin
N64vSNES wrote:I'm not positive I understood your question, I'm going to assume you are using C++.

________
|Node 1| -------------> if ( Clicked == true ) { Current == 1; }
|__ ___|

________
|Node 2|-------------> if ( Clicked == true ) { Current == 2; }
|__ ___|

________
|Node 3|-------------> if ( Clicked == true ) { Current == 3; }
|__ ___|

Code: Select all

int GetCurrent() {	
	return Current;
}

void EraseCurrent() {
	Nodes.erase(Nodes.begin() + GetCurrent()); // Nodes being the vector
}
etc...
I think thats what you mean?
Alright, sorry for the bad wording and short description everyone, I was tired when I posted that problem. Thank you all though, I think I can work N64vNES's thingy into exactly what I need to thanks man.

Re: GetCurrent??

Posted: Sun Nov 28, 2010 5:11 pm
by N64vSNES
I still don't get it but I think thats anwsered his question =]

Re: GetCurrent??

Posted: Mon Nov 29, 2010 2:12 am
by MadPumpkin
N64vSNES wrote:I still don't get it but I think thats anwsered his question =]
Basically I'm making a map editor in c++ and I'm having major problems with deleting the selected object and even MAKING an object be selected. You click on a node to select it, and after a node is selected you can delete it, or right click it to open it's properties. Now that I have a better description, do you know how I can make it so that clicking on a node/object will "set it to selected" so that I can do those things?

Re: GetCurrent??

Posted: Mon Nov 29, 2010 4:46 am
by adikid89
Sorry if the code wasn't helpful

Code: Select all

Tile* selected = 0;
//pseudocode ?
if(event.type == MouseLButtonPressed) {
   //the "algorithm" to get a tile at a mouse pos should be pretty easy
   selected = GetTileAt(event.mouse.x, event.mouse.y);
}
if(event.type == KeyDeletePressed) {
   if(selected) selected->ResetToDefaultTile();
}
if(event.type == MouseRButtonPressed) {
   if(selected) OpenPropertiesDialog(selected);
}


Re: GetCurrent??

Posted: Wed Dec 01, 2010 9:15 pm
by MadPumpkin
adikid89 wrote:Sorry if the code wasn't helpful

Code: Select all

Tile* selected = 0;
//pseudocode ?
if(event.type == MouseLButtonPressed) {
   //the "algorithm" to get a tile at a mouse pos should be pretty easy
   selected = GetTileAt(event.mouse.x, event.mouse.y);
}
if(event.type == KeyDeletePressed) {
   if(selected) selected->ResetToDefaultTile();
}
if(event.type == MouseRButtonPressed) {
   if(selected) OpenPropertiesDialog(selected);
}

This and NES's will be great if I work them together. The game isn't tile based in that way though, it uses backdrops like this for example.
Image

So it's not supposed to just make it a different tile, it's going to remove it from the Vector entirely.

Re: GetCurrent??

Posted: Sat Dec 04, 2010 12:29 pm
by adikid89
You can check a Rect collision on the objects with the mouse coords where the click happened. If there was a collision with the rect of a object (the rect is the image's x,y pos and w/h)... then you do find out the mouse coords relative to the rect, and then check the pixel at that pos. If the pixel's color is black(or whatever dummy color you use to mask it) you skip it...cause it means it wasn't clicked in a proper position. But..if the color isn't black... then make the current object be select.

Also the removing part should be really easy... if you're using a vector...