@DavidAGK
AGK is missing the SetTextOffSet() and GetTextOffSetX, GetTextOffSetY() commands.
What makes placing text into a Sprite unnecessary complecated.
I reseted the Sprites-OffSet to 0, 0 and made so my calculations
// Project: SkeletonGUI
// Created: 19-11-25
// 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)
SetSpriteOffset(temp.spriteID,0,0) // for Rotation problems, or against
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 vecFENGadgetList.length
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()
global FEN_maxJ = 4
global FEN_ScrollSpeed# = 1000
global FEN_ZoomSpeed# = 1
global FEN_minZoom# = 0.1
global FEN_maxZoom# = 4
#constant FEN_InputScrolling = 1
#constant FEN_InputZooming = 2
FENCreateGadgetColors()
FENCreateGadgetImages() // needs Colors before!
FENDummySprite = CreateDummySprite()
FixSpriteToScreen(FENDummySprite,1)
img = CreateImageColor(255,0,0,255)
FENMousePoint = CreateSprite(img)
EndFunction
Function FENInitMouse()
// ------ if mouse exists ----
global OldMouseX# = 0
global OldMouseY# = 0
OldMouseX# = GetRawMouseX()
OldMouseY# = GetRawMouseY()
//------------------------------
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]
x# = 0
y# = 0
tempAngle# = GetSkeleton2DAngle(temp.GadgetListID) //+ GetSpriteAngle(temp.SpriteID)
x# = x# + GetFENPointRotationX(GetSpriteX(temp.SpriteID) ,GetSpriteY(temp.SpriteID),tempAngle#) // SetSpriteOffSet() maybe could made this unnecessary
y# = y# + GetFENPointRotationY(GetSpriteX(temp.SpriteID) ,GetSpriteY(temp.SpriteID),tempAngle#)
// x# = x# + GetFENPointRotationX(GetSpriteOffsetX(temp.SpriteID) ,GetSpriteOffsetY(temp.SpriteID),tempAngle#)
// y# = y# + GetFENPointRotationY(GetSpriteOffsetX(temp.SpriteID) ,GetSpriteOffsetY(temp.SpriteID),tempAngle#)
x# = x# + GetSkeleton2DX(temp.GadgetListID) //- GetSpriteOffsetX(temp.SpriteID)
y# = y# + GetSkeleton2DY(temp.GadgetListID) //- GetSpriteOffsetY(temp.SpriteID)
tempAngle# = tempAngle# + GetSpriteAngle(temp.SpriteID)
// -- Debug -----
// print(Str(GetSpriteOffsetX(temp.SpriteID)))
// print(Str(GetSpriteOffsetY(temp.SpriteID)))
// --------------
FENSetSpriteValues(FENDummySprite,x#,y#,GetSpriteWidth(temp.SpriteID),GetSpriteHeight(temp.SpriteID), tempAngle#)
SetTextAngle(temp.textID, tempAngle#)
SetTextPosition(temp.textID, x#, y#)
SetTextSize(temp.textID, GetSpriteHeight(temp.SpriteID) * 1)
//--------------- MOUSE and VIEW ----------------------
fMx# = ScreenToWorldX(GetRawMouseX())
fMy# = ScreenToWorldY(GetRawMouseY())
fMx# = (fMx# - GetViewOffsetX()) * GetViewZoom()
fMy# = (fMy# - GetViewOffsetY()) * GetViewZoom()
//--------------- MOUSE and VIEW END ----------------------
If GetSpriteHit(fMx#, fMy#) = FENDummySprite
SetSpriteImage(temp.spriteID,FENGadgetImage.HoverImgID)
Else
SetSpriteImage(temp.spriteID,FENGadgetImage.UpImgID)
EndIf
/*
Print("S:"+Str(GetSpriteHit(fMx#,fMy#)))
Print("fMx:"+Str(fMx#,2)+"fMy:"+Str(fMy#,2))
Print("x#:"+Str(x#,2)+"y#:"+Str(y#,2))
*/
// 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)
FENResetView()
For i = 0 to 5
SetSpriteAngle(vecFENGadgetList[CreateFENBtn(menuID,5 ,31*i,100,28,"Button ["+Str(i)+"]")].spriteID,10*i)
Next
//CreateFENBtn(menuID, 5,20,120,20,"Moin")
SetSkeleton2DRotation(menuID,30) // Rotation is a problem
SetSkeleton2DBoneScale(menuID,0,1,1)
//GetSkeleton2DBon
FENInitMouse()
global InputMode = FEN_InputScrolling
do
Print( Str(ScreenFPS(),2) + " : "+" InputMode: "+ Str(InputMode))
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_keyboardInput()
FL_gamepadInput()
// FL_mouseInput()
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
// ------------- Game Input ---------------------------------
Function FL_keyboardInput()
If InputMode = FEN_InputScrolling
FENScrollView(-GetRawKeyState(65),-GetRawKeyState(87))
FENScrollView( GetRawKeyState(68), GetRawKeyState(83))
Elseif InputMode = FEN_InputZooming
FENZoomView(-GetRawKeyState(87))
FENZoomView( GetRawKeyState(83))
EndIf
If GetRawKeyPressed(71)
InputMode = FENGetSwapFloat(InputMode, FEN_InputScrolling, FEN_InputZooming)
EndIf
If GetRawKeyPressed(82)
FENResetView()
EndIf
EndFunction
Function FL_mouseInput()
MouseDeltaX# = (OldMouseX# - WorldToScreenX(GetRawMouseX()))/1
MouseDeltaY# = (OldMouseY# - WorldToScreenY(GetRawMouseY()))/1
Print(Str(MouseDeltaX#))
Print(Str(MouseDeltaY#))
If InputMode = FEN_InputScrolling
FENScrollView(MouseDeltaX#,MouseDeltaY#)
Elseif InputMode = FEN_InputZooming
FENZoomView(MouseDeltaY#)
EndIf
OldMouseX# = WorldToScreenX(GetRawMouseX())
OldMouseY# = WorldToScreenY(GetRawMouseY())
EndFunction
Function FL_gamepadInput()
For j=1 to FEN_maxJ
If GetRawJoystickExists(j) // If GetRawJoystickName() // geht nicht auf Android :-(
Print ("Joy: "+Str(j)+" : "+GetRawJoystickName(j))
If InputMode = FEN_InputScrolling
FENScrollView(GetRawJoystickX(j),GetRawJoystickY(j))
Elseif InputMode = FEN_InputZooming
FENZoomView(GetRawJoystickY(j))
EndIf
If GetRawJoystickButtonPressed(j,2) // Kreis
InputMode = FENGetSwapFloat(InputMode, FEN_InputScrolling, FEN_InputZooming)
EndIf
If GetRawJoystickButtonPressed(j,1) // Menu // Dreieck auf PSclassic-USB_Pad
EndIf
If GetRawJoystickButtonPressed(j,10) or GetRawKeyPressed(82) // [START], KEY_R
FENResetView()
EndIf
For k=1 to 16
If GetRawJoystickButtonState(j,k)
Print("Key:"+Str(k))
EndIf
Next
EndIf
Next
Endfunction
Function FENResetView()
SetViewOffset(0,0)
SetViewZoom(1)
EndFunction
Function FENScrollView(inputX#, InputY#)
SetViewOffset(GetViewOffsetX()+inputX# * GetFrameTime() * FEN_Scrollspeed#, GetViewOffsetY()+inputY# * GetFrameTime() * FEN_Scrollspeed#)
EndFunction
Function FENZoomView(input#)
minZoom# = FEN_minZoom#
maxZoom# = FEN_maxZoom#
ZoomSpeed# = FEN_ZoomSpeed#
If (input#<0 and GetViewZoom() > minZoom#) or (input#>0 and GetViewZoom()<maxZoom#)
SetViewZoom(GetViewZoom()+input# * GetFrameTime() * ZoomSpeed#)
EndIf
EndFunction
Function FENGetSwapfloat(Input#, value1#, value2#) // list of values ... von Liste von Werten
If Input# = Value1#
Input# = Value2#
ElseIf InputMode = Value2#
Input# = Value1#
EndIf
EndFunction Input#
// ------------- Game Input End ---------------------------
I tricked the Skeleton-System with my own "Animation" to use it for a menu
I used the files: empty1px1px.png // it is a 1 by 1 Pixel PNG file, not transparent for Debug purpose.
OneBoneOnly.scon a Skeleton Animation created with Spriter with only one Bone. (because at this moment we have no "CreateSkeleton2DBone... command", but can load Skeleton2D-Animations)