text align

O Ilusionista

Captain 100K
Look at the picture bellow:
574056799124617,O.jpg


There isn't a way to align the second player text at RIGHT not at left, as all other texts? Or there is a way to include this on the engine code?
 
Hmm... I wish something like that could work. That's what I got in mind. The name on the right below (Captain America). There needed to be like a reverse offset for the last letter of the name (since we have the regular offset that's close to the first letter of the name).
 
You can do this if you draw your text with script.  You can use the strwidth function to get the width of a string:

Code:
int strwidth(char string, int font)

Just subtract that width from the X coordinate where you want the string to end, and you now have the X coordinate for a right-aligned string.
 
I am lost now. How can I draw text with script? Do I need to go with text object or handling string? I've been trying to make the right-sided alignment with drawstring, but still, it's aligned left.

This is what I have so far and it's in update.c:
Code:
int strwidth(char cString, int iFont){
	//int     P2x      = gettextobjproperty(p2Name, "x");      //Return X.
	//cString =
	//iFont = 
	//drawstring(strwidth(250-cString), 43, iFont, "");
	drawstring(cString-strwidth("",0), 43, iFont, ""); //drawstring(x-strwidth(string,font),y,font,text);
}

For player 2's name and score (ignore the dash):
Code:
p2score 281 55 45 -26 250 43 0

EDIT: @White Dragon and @Piccolo: How do you guys use strwidth function? What I want is to subtract the width of string from the X coordinate according to Plombo.

White Dragon, I was looking at your strwidth function and you used hres (openborvariant of hresolution) and cpyrs in your title script. I wonder how you make it work.

Code:
 drawstring(hres/2-strwidth(cpyrs, 0)/2,227,0,cpyrs);

I do understand that hres is used under void main for the title script.

Code:
int hres = openborvariant("hresolution");

And the text of CPRYS at the top in the title script for the very bottom of the screen in game:

Code:
#define CPYRS "white dragon software>  2013/15"
 
O Ilusionista, I know you have wanted the right-aligned text for player 2. And guess what? I found a way how to do it last night, all thanks to Plombo and Piccolo. You can do this in update.c, but I don't know what your current update.c looks/is like. Let me put this on my own I made up (for only name), but this is based on the solution which Piccolo did.

update.c:

Code:
void main(){
	PlayerNamePos(); //Player name position function
}

void PlayerNamePos(){ //Player name position
	void p1 = getplayerproperty(0, "entity"); //Player 1
	void p2 = getplayerproperty(1, "entity"); //Player 2

	int hres = openborvariant("hresolution"); //Screen width resolution

	if(p1 != NULL()){ //Player 1 not empty?
		char p1Name = getentityproperty(p1, "name"); //Player 1's name
	}

	if(p2 != NULL()){ //Player 2 not empty?
		char p2Name = getentityproperty(p2, "name"); //Player 2's name
	
		if(p2Name){ //Player 2 name
			drawstring(hres-27-strwidth(p2Name, 0), 55, 0, p2Name); //Right-aligned player name on player 2 side
		}
	}
	
}

I named the function PlayerNamePos for player name position. You need to add screen width ("hresolution") to it if you want to make an alignment. As Plombo said:

Just subtract that width from the X coordinate where you want the string to end, and you now have the X coordinate for a right-aligned string.

Thanks Plombo and Piccolo. :)

EDIT: After you made a right alignment for player 2 and are comfortable with it, you can freely hide player 2's name in levels.txt, leaving your right-aligned player 2 name there.

EDIT 2: Just checked my post and corrected from p2Ent to p2 in script because of the variable name (e.g. p2 for player 2 for being called). I made a mistake on it before. Now it's fixed.
 
Back
Top Bottom