I decided to make a isometric game using c++ and cocos2d-x.
Each isometric tile has an X and an Y coordinate, incresing 1 per tile moved. This is how I am converting tile to screen coordinates.
cocos2d::CCPoint WorldPos::convertToScreen(){
cocos2d::CCPoint posScreen;;
posScreen.x=(this->x)*(TILE_WIDTH/2) + (this->y)*-TILE_HEIGHT;
posScreen.y=(this->x)*(TILE_HEIGHT/2) + (this->y)*(TILE_HEIGHT/2);
return posScreen;
}
The tiles are all 40px wide and 20px tall.
now I need a function to convert these world coordinates (the isometric coordinates) back to screen coordinates. something like
WorldPos* WorldPos::convertToWorld(cocos2d::CCPoint &point)
I can’t seem to figure this one out, am I doing it all wrong and should I do positioning is a diffirent way or is there some kind of calculation that I can’t figure out?
Try:
Logic:
where
Px,Py,Wx,WyareCCpoint::x,CCPoint::y,WorldPos::x,WorldPos.y, respectively