SpriteCandy - HUD_GetObjectX on Groups?

Blitz3D Forums/Blitz3D Programming/SpriteCandy - HUD_GetObjectX on Groups?

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

I dont think with the standard functions you can do this. Perhaps you could make your own SC function similar to :

Function HUD_GetGroupX# (ObjectID%)
	Local itemcount
	Local objx#
	Local averageX#
	Local xtotal#
	Local Obj.SC_Object  = Object.SC_Object(ObjectID)
	
	; HANDLE GROUP? ----------
	If Obj = Null Then
		Local Group.SC_Group    = Object.SC_Group    (ObjectID)
		Local Item.SC_GroupItem = Object.SC_GroupItem(ObjectID)
		; FIRST GROUP CALL?
		If Group <> Null
			itemcount=0
			For Item = Each SC_GroupItem
				If Item\GroupID = Handle(Group) Then 
					; loop through and find the x value of all the objects
					objx#=HUD_GetObjectX# (Handle(Item))
					xtotal=xtotal+objx
					itemcount=itemcount+1
				EndIf
			Next
			averageX#=xtotal/itemcount
			Return averageX#
		End If
		; NOTHING FOUND?
		If Group = Null And Item = Null And Obj = Null Then RuntimeError SC_BreakText("HUD_GetGroupX||The specified object or group does not exist.",50)
	End If
End Function



I haven't tested the above but it should work or at least point you in a direction. I looked at the SC code where it handled grouped objects and made a new function to loop through the objects in the group to find the average X value of the objects. Obviously there are many ways to decide on what x value you want e.g. the smallest x value in the group, or the largest x value but this depends on what you want. Hope this helps.

Cheers,


Unc