Hi guys,
i've got another problem now.I made a slider because my intention is to use this for scrolling inventory and i can't figure out how to manage the sprite properly.If i use slider(1, 264,100, 200, 20,
0, 64) then sprite is hidden once and i don't know how to draw it back.If i use slider(1, 264,100, 200, 20,
-64, 64) it's hidden at one place and showed at another.I keep messing arround and can't find the solution.Also if you use -64 and scroll fast it cut's the sprite in pieces.Here is the code:
sync on : sync rate 60
REM load an image
load image "C:\Users\lusi\Desktop\rus\items\434.png", 4
REM create a memblock from the image
make memblock from image 1, 4
make memblock from image 2, 4
REM get the image's width and height
widthMax = memblock dword(1,0)
heightMax = memblock dword(1,4)
iy# = 100
Type SliderObject
focus as boolean
offset as integer
thumb as integer
value as float
Endtype
dim sliders(1) as SliderOBject
Global _MFlag = 0
Global _MClick = 0
do
_MClick = mouseclick()
slider(1, 264,100, 200, 20, 0, 64)
if _MClick > 0 : _MFlag = 1 : else : _MFlag = 0 : endif
if draw_height > 0
for x = 1 to widthMax
for y = 1 to draw_height
if draw_height <= heightMax
location = ((y-1)*widthMax + x - 1)*4 + 12
endif
REM set each pixel in the image to a random color
write memblock dword 1, location, argb2(255,255, 255, 0)
next y
next x
endif
if draw_height < 0
for x = 1 to widthMax
for y = heightMax to 1 step - 1
if draw_height > heightMax-heightMax*2
if y = heightMax
location = ((heightMax+draw_height)*widthMax + x - 1)*4 + 12
else
location = ((heightMax+draw_height-1)*widthMax + x - 1)*4 + 12
endif
endif
REM set each pixel in the image to a random color
`if height > -64
write memblock dword 1, location,memblock dword (2,location)
`endif
next y
next x
endif
remstart
if mouseclick() = 2
if draw_height > 0 then draw_height = draw_height - 63
dec draw_height
inc iy#
endif
if mouseclick() = 1
if draw_height < 0 then draw_height = draw_height + 63
inc draw_height
dec iy#
endif
remend
iy# = 200-sliders(1).value
draw_height = sliders(1).value
if draw_height > 64 then draw_height = 64
if draw_height < -64 then draw_height = -64
REM create a new image from the memblock data
make image from memblock 3, 1
sprite 1,mousex(), mousey(), 4
`sprite 2,mousex()+widthMax+5, mousey(), 3
`paste image 3,mousex()+widthMax+5, mousey(),1
paste image 3,200,int(iy#),1
text 0,40,"FPS: "+str$(screen fps())
text 0,20,"draw_height"+str$(draw_height)
text 0,0,"iy"+str$(iy#)
sync
loop
`Just call argb() like you would rgb(), but send an extra variable for alpha.
function argb2(r, g, b, a)
col = a<<24 || r<<16 || g<<8 || b
endfunction col
function slider(id, x, y, width, height, minVal, maxVal)
newmousey = mousey()
ink rgb(255,255,255),0
text x-text width(str$(minVal))-2, y, str$(minVal)
text x+width+2, y, str$(maxVal)
center text x+sliders(id).thumb, y-text height(" ")-2, str$(sliders(id).value)
ink rgb(110,244,2), 0
box x, y, x+height, y+width
ty = sliders(id).thumb
ink rgb(255,255,0), 0
box x, y+ty, x+height, y+ty+height
if _MClick = 1
if _MFlag = 0
if mouseHotspot(x, y+ty, x+height, y+ty+height) = 1 and sliders(id).focus = 0
sliders(id).focus = 1
sliders(id).offset = mousey() - sliders(id).thumb
endif
_MFlag = 1
endif
if sliders(id).focus = 1
sliders(id).thumb = mousey() - sliders(id).offset
if sliders(id).thumb < 0 then sliders(id).thumb = 0
if sliders(id).thumb > width-height then sliders(id).thumb = width-height
t# = sliders(id).thumb / (width-height+0.0)
sliders(id).value = minVal + (maxVal - minVal)*t#
endif
else
sliders(id).focus = 0
endif
endfunction
function mouseHotspot(x1, y1, x2, y2)
if mousex() > x1 and mousex() < x2 and mousey() > y1 and mousey() < y2 then exitfunction 1
endfunction 0
Coding is My Kung Fu!
And My Kung Fu is better than Yours!