In layer mode you should not constantly create new box and brush layers, the layers may only be created once.
Write an
OpenResourceMonitor() in your example to see what happens.
I see two ways to achieve the desired effect. Either you create Brush 1 with a mask and move the layer and redraw the mask in the _main() function if necessary or you place an additional layer as a window in front of the Brush 1 layer.
I have quickly hacked together the second variant so that you can see the principle. The checks of the boundaries have not yet been adapted.
Code: Select all
@DISPLAY 1,{Width = 640, Height = 350, Mode = "fullscreen", Layers = True}
@BRUSH 1,"bg.png"
@BRUSH 3,"exp2_0.png", {LoadAlpha = True}
explosion = CreateAnim(1, 3, 64, 64, 16, 4)
part_x = 20 ; x coordinate of the part of landscape
part_y = 0 ; y coordinate of shown part
win_width = 200 ; width of the shown part of landscape
win_height = 200 ; height of ...
win_x = GetAttribute(#DISPLAY,1,#ATTRWIDTH)/2 - win_width / 2 ; koordinaten für sichtfenster
win_y = GetAttribute(#DISPLAY,1,#ATTRHEIGHT)/2 - win_height / 2
cross_x = #CENTER ;GetAttribute(#DISPLAY,1,#ATTRWIDTH)/2
cross_y = #CENTER ;GetAttribute(#DISPLAY,1,#ATTRHEIGHT)/2
maxwidth = GetAttribute(#BRUSH,1,#ATTRWIDTH) - win_width/2 ; das sichtbare fenster abziehen
maxheight = GetAttribute(#BRUSH,1,#ATTRHEIGHT) - win_height/2
i=0
explode=False
Function _explode(x,y)
expanim = PlayAnim(1, x, y, {Async = True});, table])
Repeat
done = AsyncDrawFrame(expanim)
VWait
Until done = True
explode=False
EndFunction
Function _main()
If IsKeyDown("left") Then part_x=part_x+1
If IsKeyDown("right") Then part_x = part_x-1
If IsKeyDown("up") Then part_y = part_y+1
If IsKeyDown("down") Then part_y=part_y-1
If IsKeyDown("space") Then explode=True
If part_x<0 And win_x<320
part_x = 0
win_x = win_x + 1
EndIf
If part_x>= maxwidth Then part_x=maxwidth
If part_y<0 Then part_y = 0
If part_y>maxheight Then part_y = maxheight
SetLayerStyle(1, {X=part_x, Y=part_y})
If explode=True Then _explode(cross_x,cross_y)
EndFunction
EscapeQuit(True)
DisplayBrush(1,part_x,part_y)
CreateBrush (4,GetAttribute(#DISPLAY,1,#ATTRWIDTH),GetAttribute(#DISPLAY,1,#ATTRHEIGHT), #BLACK)
SelectBrush (4)
SetFillStyle(#FILLCOLOR)
Box(win_x, win_y, win_width, win_height,#GRAY)
EndSelect()
SetBrushTransparency(4, #GRAY)
DisplayBrush(4,0,0)
CreateBrush (2,32,32)
SelectBrush (2)
Box(win_x, win_y, win_width, win_height,#GRAY)
Line(16,0,16,32,#YELLOW, {Thickness = "2"})
Line(0,15,32,15,#YELLOW, {Thickness = "2"})
EndSelect()
SetBrushTransparency(2, #BLACK)
DisplayBrush(2,cross_x,cross_y)
SetInterval(1, _main, 1000/50)
Repeat
WaitEvent
Forever