Help wit my game please!

Blitz3D Forums/Blitz3D Beginners Area/Help wit my game please!

Nike(Posted 2009) [#1]
ok well im making a basic rpg with pictures (Or atleast trying) and i need to get the person's name under the picture of him. Im not sure what code you need but here is a little bit of it.





Knight #51(Posted 2009) [#2]
How big are the players' pictures??


Sledge(Posted 2009) [#3]
If you want to center the text then add half the width of the image to its x coordinate and subtract half the pixel width of the text to get the appropriate x value; The y value for the text will be the ycoord of the image plus the image's height plus however much padding you want.

EDIT:
Here's a rough example. Notice that the text is treated as if it were a bitmap font, which is what you'll inevitably end up using.
Graphics 640,480,0,2
SetBuffer BackBuffer()

Const AVATAR_WIDTH% = 64
Const AVATAR_HEIGHT% = 128
Const FONT_WIDTH% = 12
Const FONT_HEIGHT% = 12

MakeAvatar("Sarah")
MakeAvatar("John")
MakeAvatar("Zed")
MakeAvatar("JJ")
MakeAvatar("X")

Color 100,255,100

While Not KeyHit(1)
	DrawAllAvatars()
	Text 10,10,"Left Mouse Button To Delete Avatars..."

	Flip True
	Cls
	
	If MouseHit(1) DeleteAvatar()
Wend
End




Global Avatar_Count% = 0

Type TAvatar
	Field piccy%
	Field name$
End Type


Function MakeAvatar(name_arg$)
	Color 100+Rand(155),100+Rand(155),100+Rand(155)
	Rect 0,0,AVATAR_WIDTH,AVATAR_HEIGHT
	
	newAvatar.TAvatar = New TAvatar
	newAvatar\name = name_arg
	newAvatar\piccy = CreateImage(AVATAR_WIDTH,AVATAR_HEIGHT)
	GrabImage newAvatar\piccy,0,0
	Cls
	
	Avatar_Count = Avatar_Count+1
End Function

Function DeleteAvatar()
       	If Avatar_Count = 0 Return

	Local avatarToDelete.TAvatar = First TAvatar
	FreeImage avatarToDelete\piccy
	Delete avatarToDelete 
	Avatar_Count=Avatar_Count-1
End Function

Function DrawAllAvatars()
	If Avatar_Count = 0 Return
	
	Local xSpace% = GraphicsWidth()/(Avatar_Count+1)
	Local currentAvatarIndex% = 1

	For currentAvatar.TAvatar = Each TAvatar
		DrawBlock currentAvatar\piccy,(currentAvatarIndex*xSpace)-(AVATAR_WIDTH*.5),GraphicsHeight()-AVATAR_HEIGHT-10-FONT_HEIGHT
		DrawName(currentAvatar\name,(currentAvatarIndex*xSpace)-(AVATAR_WIDTH*.5),GraphicsHeight()-10-FONT_HEIGHT)

		currentAvatarIndex = currentAvatarIndex+1
	Next
End Function

Function DrawName(string_arg$, xPos_arg%, yPos_arg%)
	Local pixelWidth% = Len(string_arg)*FONT_WIDTH
	Local centeredX% = (xPos_arg+(AVATAR_WIDTH*.5)) - (pixelWidth*.5)
	
	For currentCharIndex = 0 To Len(string_arg)
		Text centeredX+(currentCharIndex*FONT_WIDTH),yPos_arg,Mid(string_arg,currentCharIndex+1,1)
	Next
End Function



Nike(Posted 2009) [#4]
i tried your code and i cant figure it out still. :( the people's pictures are 50 by 50 pixels


Ross C(Posted 2009) [#5]
Location of text =

NOTE: START X and START Y are the top corner your using to draw the image.

x = (the START X + (HALF OF THE WIDTH of the image)) - (HALF the width of the text)

y = the START Y + HEIGHT of the image + SPACING between the text and the picture


Ross C(Posted 2009) [#6]
Note, the above is if you wish to centre some text. Practical example:


message$ = "John"

image = createimage(50,50)

startX = 50
startY = 50

spacing = 10 ; 10 pixels spacing.

DrawImage image,startX,startY

Text (startX + (imagewidth(image)/2)) - (stringwidth(message)/2) , startY + imageheight(image) + spacing, message




Nike(Posted 2009) [#7]
ok but my people move and i would like to make the text under and folow them. That way people know which person is which


Ross C(Posted 2009) [#8]
And that will happen. startX and startY are simply variables. Just adjust them as needed, like when the player moves. Simple variable stuff ;o)


Nike(Posted 2009) [#9]
Ok well, im really bad at this stuff. i cant really program and the biggest program i made is a 2D rpg. I found some code with pictures and moveing people and im trying to make an rpg with all the code i got. here is what i have so far. Help please!!!




KillerX(Posted 2009) [#10]
Text x,y,message,1,0;

the two optional parameters centre the string.


Ross C(Posted 2009) [#11]
You need to put the text command and the image drawing stuff in the main loop, or else it will be drawn once and deleted.


AJ00200(Posted 2009) [#12]
you're going to want to use the entity parent command to set the picture (name) as a child element to the (normal) picture.


Ross C(Posted 2009) [#13]
He is using 2d graphics, so you can't use entityparent in this instance.