SpriteCandy - HUD_GetObjectX on Groups?

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

Mortiis(Posted 2008) [#1]
I can't get the X coord value of an object group. Is it possible?

I have 2 images -a tire and a body- forming a car, they are grouped
like this;

this\car = HUD_CreateGroup()
HUD_AddToGroup( this\body, this\car )
HUD_AddToGroup( this\tire, this\car )


I get an error "the Specified object doesn't exist" when I do this;

this\x = HUD_GetObjectX( this\car )


Thanks in advance.


GIB3D(Posted 2008) [#2]
Try
this.car = HUD_CreateGroup()



Mortiis(Posted 2008) [#3]
No that way you can create a type, not a group in Sprite Candy.
There is no problem with my group creation code.

Problem is, when I try to get X of the group of sprites, it doesn't act like
they are an object. But there is no problem when I use HUD_FX_Scale this\car, 1.3, 1.3, 0 or HUD_MoveObject this\car, this\speed, 0.

Also you cannot use movement effects like HUD_FX_Wave with HUD_MoveObject code on the same object. It just waves or moves but doesn't do both.

Any help is greatly appreciated.


Uncle(Posted 2008) [#4]
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