Hey! Your problem can be fixed simply by using nodes. If you create a list of center points with game coordinates or screen coordinates attached to each node, then you only have to retrieve the node you need at any point.
I am going to create a GUI system for my rpg game maker using screen nodes. It will bring menus up, buttons, allow for drag and drop of inventory items and even node snapping.
Check out my ISOMAP GENERATOR for examples of using nodes.
Here is the create map function that creates a square grid graph of nodes:
- Code: Select all
void CreateMap()
{
//Variables for map creation
int mh;
int mw;
//temporary x,y
int tX = 0;
int tY = 0;
//number of tiles
int tNum = 0;
// MAPHEIGHT is a const that gives the height of the grid, declared as a global variable
for(mh = 0; mh < MAPHEIGHT; ++mh)
{
// TILESIZE[] is a const array with the tiles length and width, declared as a global variable
// This formula gives you the center of each tile on the Y axis
tY = (TILESIZE[0] * mh) + (TILESIZE[0]/2);
// MAPWIDTH is a const that gives the height of the grid, declared as a global variable
for(mw = 0; mw < MAPWIDTH; ++mw)
{
// This formula gives you the center of each tile on the X axis
tX = (TILESIZE[1] * mw) + (TILESIZE[1]/2);
// Increases node X based on MAPWIDTH at the time of loop, tnum is the node ID
NodeX[tNum] = mw;
// increases node Y based on MAPHEIGHT at the time of loop
NodeY[tNum] = mh;
// This is node data used for the finding game or screen coordinates
NodeID[tNum] = tNum;
NodeX[tNum] = tX;
NodeY[tNum] = tY;
tNum = tNum +1;
}
}
}
//This is a 2D map creation loop. This will be used later to create the screen nodes.
That code doesn't link the nodes to the screen, but it can be used to link the nodes to the screen, you just have to add the extra code that makes the item go to the coordinates based off the node.
Basically:
- Code: Select all
PSUEDOCODE:
// if X and Y match return the node
for(x= 0; clickedscreenX == NodeX[x]; ++x)
if( clickedscreenY == NodeY[x])
{ return NodeID[x]; }
Now that code won't ACTUALLY work, because you would have to click the center pixel of each tile area in order to get the exact x,y but you can find a different formula that searches within the TILESIZE[]. But, it gives you an idea of how you would do it.
Also for your transparency issue, have you tried using an Actor* variable to store the actor that you've created and then doing something like
- Code: Select all
Actor* myActor;
myActor = CreateActor();
myActor->transp = 0.0;
Haven't used it, but it should work in theory.