A working proof of concept. The Angles gave me a headache, because I didn't know, that the SpriteOffSet has to be set after a re-size.
Maybe there is something still wrong with GetSpriteHit ... a Bug in App Game Kit, because the Hit-Mask is not there where the visual representation of the Sprite is.
It works, and I guess, it also could be done without the Dummy-Sprite I used. I used it, to track down the problem with the offset of the hit-detection.
I guess, it is still odd behavior.
// Project: SkeletonGUI
// Created: 19-11-25, xaby
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "SkeletonGUI" )
SetWindowSize( 1280, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1280, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
// Project: FLEVEL
// Created: 19-11-16
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "FLEVEL" )
SetWindowSize( 1280, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1280, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30000, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
//--------------------------------------------------------------------
menuID = LoadSkeleton2DFromSpriterFile("OneBoneOnly.scon",1,0)
img = CreateImageColor(100,200,100,255)
spr = CreateSprite(img)
SetSpriteSize(spr,100,200)
FixSkeleton2DToScreen(menuID,1)
FixSpriteToSkeleton2D(spr, menuID, 0, 0)
FixSpriteToScreen(spr,1)
SetSkeleton2DPosition(menuID, 1100,100)
SetSkeleton2DRotation(menuID, 0)
img = CreateImageColor(200,0,200,255)
spr = CreateSprite(img)
SetSpriteSize(spr,200,50)
SetSpritePosition(spr,300,300)
SetSpriteAngle(spr,60)
//SetSkeleton2DPosition(menuID, 31000,31000)
// ------------ GUI ---------------------
Type FENGadgetColor
Up as integer
Down as integer
Hover as integer
NotActive as integer
TextColor as integer
RED as integer
MAGENTA as integer
EndType
Global FENColor as FENGadgetColor
Function FENCreateGadgetColors()
FENColor.Up = MakeColor(230,230,230,255) // White - Light-Grey
FENColor.Down = MakeColor(150,255,150,255)// Green
FENColor.Hover = MakeColor(200,230,200,255)// light Green
FENColor.NotActive = MakeColor(100,100,100,255)
FENColor.TextColor = MakeColor(0,30,255,255)
FENColor.RED = MakeColor(255,0,0,255) // for debug and so on
FENColor.MAGENTA = MakeColor(255,0,255,255) // for debug and so on
EndFunction
Type FENGadgetImageID
UpImgID as integer
DownImgID as integer
HoverImgID as integer
NotActiveImgID as integer
EndType
Global FENGadgetImage as FENGadgetImageID
Function FENCreateGadgetImages()
FENGadgetImage.UpImgID = CreateImageColor(GetColorRed(FENColor.Up),GetColorGreen(FENColor.Up),GetColorBlue(FENColor.Up),GetColorAlpha(FENColor.Up))
FENGadgetImage.DownImgID = CreateImageColor(GetColorRed(FENColor.Down),GetColorGreen(FENColor.Down),GetColorBlue(FENColor.Down),GetColorAlpha(FENColor.Down))
FENGadgetImage.HoverImgID = CreateImageColor(GetColorRed(FENColor.Hover),GetColorGreen(FENColor.Hover),GetColorBlue(FENColor.Hover),GetColorAlpha(FENColor.Hover))
FENGadgetImage.NotActiveImgID = CreateImageColor(GetColorRed(FENColor.NotActive),GetColorGreen(FENColor.NotActive),GetColorBlue(FENColor.NotActive),GetColorAlpha(FENColor.NotActive)) // dark-grey
EndFunction
Type FENGadget
textID as integer
spriteID as integer // imageID
imageID as integer // everytime the same?
GadgetType as integer // Btn, checkbox
GadgetState as integer // up, down, hover, checked // like events
Active as integer
Visible as integer
GadgetListID as integer // nested, 0 if no GadgetList is in use // Bone!
GadgetListBone as integer // mostly always zero
EndType
global vecFENGadgetList as FENGadget[] // buttons and windows
Function CreateFENBtn(WindowSkeletonID, x#, y#, xl#, yl#, text$)
temp as FENGadget
temp.imageID = FENGadgetImage.UpImgID
temp.spriteID = CreateSprite(temp.imageID)
SetSpriteSize(temp.SpriteID,xl#,yl#)
SetSpritePosition(temp.SpriteID,x#,y#)
temp.textID = CreateText(text$)
SetTextSize( temp.textID, yl#)
SetTextPosition(temp.textID,x#,y#)
SetTextColor(temp.textID,GetColorRed(FENColor.TextColor),GetColorGreen(FENColor.TextColor),GetColorBlue(FENColor.TextColor),GetColorAlpha(FENColor.TextColor))
temp.GadgetListID = WindowSkeletonID
temp.GadgetListBone = 0
FixSpriteToSkeleton2D(temp.SpriteID, temp.GadgetListID, temp.GadgetListBone, 0)
FixSpriteToScreen(temp.SpriteID,1) //
FixTextToScreen(temp.textID,1)
vecFENGadgetList.insert(temp)
EndFunction
Function GetFENPointRotationX(x# as float,y# as float,angle# as float)
value# = x#*cos(angle#)-y#*sin(angle#)
EndFunction value#
Function GetFENPointRotationY(x# as float,y# as float,angle# as float)
value# = y#*cos(angle#)+x#*sin(angle#)
EndFunction value#
Global FENDummySprite as integer
Global FENMousePoint as integer // is a Sprite
Function FENInit()
FENCreateGadgetColors()
FENCreateGadgetImages() // needs Colors before!
FENDummySprite = CreateDummySprite()
FixSpriteToScreen(FENDummySprite,1)
img = CreateImageColor(255,0,0,255)
FENMousePoint = CreateSprite(img)
EndFunction
Function FENSetSpriteValues(SpriteID, x#, y#, xl#, yl#, angle#)
SetSpriteSize(SpriteID,xl#, yl#)
SetSpritePosition(SpriteID,x#,y#)
SetSpriteAngle(SpriteID, angle#)
SetSpriteOffset(SpriteID,0,0) // --> Drawing and HitPoint otherwise not the same
EndFunction
Function FENUpdate()
temp as FENGadget
For i=0 to vecFENGadgetList.length
temp = vecFENGadgetList[i]
tempAngle# = GetSkeleton2DAngle(temp.GadgetListID)+GetSpriteAngle(temp.SpriteID)
x# = GetFENPointRotationX(GetSpriteX(temp.SpriteID),GetSpriteY(temp.SpriteID),tempAngle#) // SetSpriteOffSet() maybe could made this unnecessary
y# = GetFENPointRotationY(GetSpriteX(temp.SpriteID),GetSpriteY(temp.SpriteID),tempAngle#)
x# = x# + GetSkeleton2DX(temp.GadgetListID)
y# = y# + GetSkeleton2DY(temp.GadgetListID)
SetTextPosition(temp.textID, x#, y#)
SetTextAngle(temp.textID, tempAngle#)
fMx# = ScreenToWorldX(GetRawMouseX())
fMy# = ScreenToWorldY(GetRawMouseY())
FENSetSpriteValues(FENDummySprite,x#,y#,GetSpriteWidth(temp.SpriteID),GetSpriteHeight(temp.SpriteID), tempAngle#)
If GetSpriteHit(fMx#, fMy#) = FENDummySprite
SetSpriteImage(temp.spriteID,FENGadgetImage.HoverImgID)
Else
SetSpriteImage(temp.spriteID,FENGadgetImage.UpImgID)
EndIf
// DrawEllipse(x#,y#,10,10,FENColor.MAGENTA,FENColor.MAGENTA,1)
Next
FENSetSpriteValues(FENDummySprite,0,0,0,0,0)
EndFunction
// ----------- END GUI -----------------------------------------
FENInit()
SetViewZoom(0.3)
SetViewOffset(30000,30000)
SetViewOffset(0,0)
SetViewZoom(1)
CreateFENBtn(menuID, 5,60,100,30,"Hallo")
CreateFENBtn(menuID, 5,20,120,20,"Moin")
SetSkeleton2DRotation(menuID,20) // Rotation is a problem
do
Print( Str(ScreenFPS(),2) )
Print("Zoom: "+Str(GetViewZoom(),2))
Print(Str(GetViewOffsetX(),2)+":"+Str(GetViewOffsetY(),2))
Print(Str(GetRawMouseX(),2)+":"+Str(GetRawMouseX(),2))
Print(Str(WorldToScreenX(GetRawMouseX()),2)+":"+Str(WorldToScreenY(GetRawMouseX()),2))
FL_gamepadInput()
FENUpdate()
// DrawEllipse(GetSkeleton2DX(menuID),GetSkeleton2DY(menuID),10,10,FENColor.RED,FENColor.RED,1)
// DrawEllipse(GetRawMouseX(),GetRawMouseY(),10,10,FENColor.MAGENTA,FENColor.MAGENTA,1)
Sync()
loop
Function FL_gamepadInput()
maxJ = 4
ScrollSpeed# = 1000
ZoomSpeed# = 1
minZoom# = 0.1
maxZoom# = 4
For j=1 to maxJ
If GetRawJoystickExists(j) // If GetRawJoystickName() // geht nicht auf Android :-(
Print ("Joy: "+Str(j)+" : "+GetRawJoystickName(j))
SetViewOffset(GetViewOffsetX()+GetRawJoystickX(j) * GetFrameTime() * Scrollspeed#, GetViewOffsetY()+GetRawJoystickY(j) * GetFrameTime() * Scrollspeed#)
If (GetRawJoystickRX(j)<0 and GetViewZoom() > minZoom#) or (GetRawJoystickRX(j)>0 and GetViewZoom()<maxZoom#)
SetViewZoom(GetViewZoom()+GetRawJoystickRX(j) * GetFrameTime() * ZoomSpeed#)
EndIf
EndIf
Next
Endfunction