So I'm pretty new to Dark GDK and I was writing a function that takes an x and y position in pixels, and places a rectangle there.
The problem I'm finding is that objects like that take in -1 - 1 to be positioned in the screen.
Right now I am placing the rectangle in the X position of 500 pixels and the middle of the screen for Y, but I would like that to be changeable, without editing the function.
I would also like to scale it according to what Size the user inputs.
Hopefully someone can help.
#include "DarkGDK.h"
void createButton(int BoxID, int PosX, int PosY, int Size);
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
while ( LoopGDK ( ) )
{
createButton(1,500,dbScreenHeight()/2,100);
dbSync ( );
}
return;
}
void createButton(int BoxID, int PosX, int PosY, int Size)
{
//Box
dbMakeObjectBox(BoxID,0.5f,0.2f,0);
//Position
float BoxPosX = 0.f;
float BoxPosY = 0.f;
if(PosX > dbScreenWidth()/2)
BoxPosX = (float)PosX/dbScreenWidth();
else if(PosX < dbScreenWidth()/2)
BoxPosX = 0;
dbPositionObject(BoxID,BoxPosX,BoxPosY,1);
}
Edit:
I found a way to do it by creating a sprite, which is how I actually wanted to in the first place. I have a plain white jpg that is 75x25 pixels big. I want to create a button with this function, and I would like to be able to scale the the sprite and the text, and place them in the right spots with this function. This is what I have so far:
#include "DarkGDK.h"
void createButton(int SpriteID, int PosX, int PosY,int ImageID, char* Text, int SizePercent);
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbLoadImage("button.jpg",1);
while ( LoopGDK ( ) )
{
createButton(1,500,dbScreenHeight()/2,1,"Text",100);
dbSync ( );
}
return;
}
void createButton(int SpriteID, int PosX, int PosY,int ImageID, char* Text, int SizePercent)
{
dbDrawSpritesFirst();
dbSprite(SpriteID,PosX,PosY,ImageID);
dbOffsetSprite(SpriteID,dbSpriteWidth(SpriteID)/(SizePercent/100)/2, dbSpriteHeight(SpriteID)/(SizePercent/100)/2);
//dbSizeSprite(SpriteID,SizePercent/2,SizePercent/4);
//Text
dbInk(dbRGB(0,0,0),dbRGB(0,0,0));
//dbSetTextSize(SizePercent/100*25);
dbCenterText(PosX,PosY,Text);// - SizePercent/10,Text);
}