Thought I would give the brain-ache stuff a little break and just tinker with some game stuff and straight away while trying to attach a turret to a tank I found a missing function ... I Know, I Know, I cant find something that does not exist its an oxymoron!!
Anyhou, This seems to work, pretty happy with how easy it was to implement.
parent_id = CreateSprite(0)
SetSpriteSize(parent_id, 100, 20)
SetSpriteOffset(parent_id, 50, 10)
SetSpritePositionByOffset(parent_id, 200, 200)
SetSpriteColor(parent_id, 255,0,0,255)
child_id1 = CreateSprite(0)
SetSpriteSize(child_id1, 50, 50)
SetSpriteOffset(child_id1, 25, 25)
SetSpritePositionByOffset(child_id1, 300, 200)
SetSpriteColor(child_id1, 0,0,255,255)
child_id2 = CreateSprite(0)
SetSpriteSize(child_id2, 30, 30)
SetSpriteOffset(child_id2, 15, 15)
SetSpritePositionByOffset(child_id2, 250, 230)
SetSpriteColor(child_id2, 0,255,0,255)
child_id3 = CreateSprite(0)
SetSpriteSize(child_id3, 30, 30)
SetSpriteOffset(child_id3, 15, 15)
SetSpritePositionByOffset(child_id3, 250, 170)
SetSpriteColor(child_id3, 0,255,0,255)
child_id4 = CreateSprite(0)
SetSpriteSize(child_id4, 30, 30)
SetSpriteOffset(child_id4, 15, 15)
SetSpritePositionByOffset(child_id4, 180, 230)
SetSpriteColor(child_id4, 0,255,0,255)
child_id5 = CreateSprite(0)
SetSpriteSize(child_id5, 30, 30)
SetSpriteOffset(child_id5, 15, 15)
SetSpritePositionByOffset(child_id5, 180, 170)
SetSpriteColor(child_id5, 0,255,0,255)
// fix sprites to parent
FixSpriteToSprite(parent_id, child_id1)
FixSpriteToSprite(parent_id, child_id2)
FixSpriteToSprite(parent_id, child_id3)
FixSpriteToSprite(parent_id, child_id4)
FixSpriteToSprite(parent_id, child_id5)
do
if GetRawMouseLeftState()
MoveSprite(parent_id, 5)
TurnSpriteTo(parent_id, GetRawMouseX(), GetRawMouseY(), 0.1)
UpdateFixSpriteToSprite()
endif
Print("Press Mouse Left To Move Sprite")
Sync()
loop
// FixSpriteToSprite
Type tSprite
ParentID
ChildID
ChildOffsetX
ChildOffsetY
EndType
Global gSprite as tSprite[-1]
Function FixSpriteToSprite(parent_id, child_id)
spr as tSprite
spr.ParentID=parent_id
spr.ChildID=child_id
spr.ChildOffsetX=GetSpriteXByOffset(child_id)-GetSpriteXByOffset(parent_id)
spr.ChildOffsetY=GetSpriteYByOffset(child_id)-GetSpriteYByOffset(parent_id)
gSprite.insert(spr)
EndFunction
Function UpdateFixSpriteToSprite()
for index=0 to gSprite.length
px# = GetWorldXFromSprite( gSprite[index].ParentID, gSprite[index].ChildOffsetX, gSprite[index].ChildOffsetY )
py# = GetWorldYFromSprite( gSprite[index].ParentID, gSprite[index].ChildOffsetX, gSprite[index].ChildOffsetY )
SetSpritePositionByOffset(gSprite[index].ChildID, px#, py#)
SetSpriteAngle(gSprite[index].ChildID, GetSpriteAngle(gSprite[index].ParentID))
next
EndFunction
// ####################
// Forum Functions
function MoveSprite(spriteID, amount#)
rem get display data
dw# = getVirtualWidth()
dh# = getVirtualHeight()
aspect# = (dw# / dh#)
if aspect# = 1.0
aspect# = getDisplayAspect()
else
aspect# = 1.0
endif
a# = getSpriteAngle(spriteID)
x# = getSpriteXbyOffset(spriteID)
y# = getSpriteYbyOffset(spriteID)
setSpritePositionByOffset(spriteID,x#+cos(a#)*amount#,y#+sin(a#)*amount#*aspect#)
endfunction
function TurnSpriteTo(spriteID,x#,y#,value#)
rem get display data
dw# = getVirtualWidth()
dh# = getVirtualHeight()
aspect# = (dw# / dh#)
if aspect# = 1.0
aspect# = getDisplayAspect()
else
aspect# = 1.0
endif
dx# = x#-getSpriteX(spriteID)
dy# = y#-getSpriteY(spriteID)
ang# = getSpriteAngle(spriteID)
targ# = atanfull(dx#,dy#/aspect#)-90
diff# = targ#-ang#
while diff#>=180
diff# = diff#-360
endwhile
while diff#<=-180
diff# = diff#+360
endwhile
new# = ang# + diff# * value#
setSpriteAngle(spriteID,new#)
endfunction
Not sure where the 2 "Forum Functions" came from but I have them in an include, thanks to whoever made them.
Now, to have fun with tanks!