Hi
Is there a way to "attach" a text/sprite with another sprite ?
I would like to create some menu, buton which could be scaled for example. I have tried, but it didn't work like I want :
My test :
// Project: sprite text link ed
// Created: 2017-03-25
Global g_width,g_Height as integer
g_width = 1024
g_Height = 768
// set window properties
SetWindowTitle( "sprite & text linked" )
SetWindowSize( g_width, g_Height, 0 )
// set display properties
SetVirtualResolution( g_width, g_Height ) // doesn't have to match the window
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetClearColor(120,120,120)
Do
ScreenProfil()
loop
Function ScreenProfil()
FoldsTart // creation sprite et textes
viewX = 0
x = 100
y = 150
// profil x4
size = 40
nb = 3
w= 150 : h = 300
dim btn2[nb] as integer
dim btn[nb] as integer
dim btntxt[nb] as integer
for i = 0 to nb
btn[i] = AddSprite2(0,w,h,x+i*(w+10),y+100) : SetSpriteColor(Btn[i],50,40,40,255)
btn2[i] = AddSprite2(0,50,50,x+i*(w+10)+w-60,y+110) : SetSpriteColor(Btn2[i],150,140,140,255)
btntxt[i] = AddText2(x+w/2+i*(w+10)-20, y+110, "test"+str(i),size)
SetTextAlignment(btntxt[i],1)
next i
MaxW = g_width + 200
quit = 0
FoldEnd
repeat
if GetRawKeyPressed(27) = 1
quit = 1
endif
mx = ScreenToWorldX(GetPointerX())
my = ScreenToWorldY(GetPointerY())
if GetPointerPressed ( ) = 1
bb = GetSpriteHit(mx, my)
i1=-1
// to resize the buton& text
for i =0 to btn.length
if bb = btn[i]
i1 =i
SetTextSize(btntxt[i],0.9*size)
SetSpriteScaleByOffset(btn2[i],0.9,0.9)
exit
endif
next
SetSpriteScaleByOffset(bb,0.9,0.9)
x = viewx + GetPointerX()
clic = 1
elseif GetPointerReleased()
// to resize the buton& text
SetSpriteScaleByOffset(bb,1,1)
if i1>-1
SetTextSize(btntxt[i1],size)
SetSpriteScaleByOffset(btn2[i1],1,1)
endif
elseif GetPointerReleased() = 1
clic=0
endif
if GetPointerState()
if clic = 1
newX = GetpointerX()
newY = GetpointerY()
viewx = (x - newx)
SetViewOffset(viewx,0)
endif
endif
sync()
until quit >= 1
FoldStart // deletesprite & text
for i = 0 to btn.length
DeleteSprite(btn[i])
DeleteSprite(btn2[i])
DeleteText(btntxt[i])
next i
undim btn2[]
undim btn[]
undim btntxt[]
Foldend
end
EndFunction
function AddSprite2(img,w,h,x,y)
n = CreateSprite(img)
SetSpriteSize(n, w, h)
SetSpritePosition(n, x, y)
endfunction n
Function AddText2(x, y, txt$, size)
id = CreateText(txt$)
SetTextPosition(id, x, y)
SetTextSize(id, size)
EndFunction id
any idea ?
AGK2 tier1 - http://www.dracaena-studio.com