At first the brush had some pixels of white borders so that it would always overwrite the edges of the old position when moved. But when increasing the speed so that it would move more pixels than the border, it would leave trails. Or if I used transparency for the brush, there would be trails.
Then I thought about layers, and enabling layers did work, and there was no trails.
Next I added a second brush, making the smiley change depending on if it was going up or down.
Then when alternating the brushes, the image of the old brush would stick to its last position until next change.
I found the only way to avoid that was to move the brush outside the visible area.
Then I do have a couple of questions.
Will this create a new layer everytime the movebrush command is used, and eventually consume endless amount of memory?
Also I do not understand how these layers are displayed, asuming movebrush will create a new layer to overwrite the old brush position and redisplay it in a new position, then how can the second brush still be displayed and not overwritten by the new layer? (that is if I do not move it out of the visible area)
For brushes, I could not find a removebrush or hidebrush command. So the only way I found to move a brush from screen is to move it out from the visible area. Is that the only way?
I will put my program here.
I do suscpect that this result could have been made more easy by using sprites instead of brushes. But right now I just made this to learn about brushes and layers.
Code: Select all
windowwidth = 1280
windowheight = 720
CreateBGPic(1, windowwidth, windowheight, #WHITE)
DisplayBGPic(1)
@DISPLAY {title = "Moving smiley", ScaleMode = #SCALEMODE_AUTO, ScaleFactor=0.5, sizeable = True}
x = 0
y = 0
EnableLayers()
LoadBrush(1, "c:/temp/Hollywood/scripts/smile.png", {Transparency = #WHITE}) ;
LoadBrush(2, "c:/temp/Hollywood/scripts/notsmile.png", {Transparency = #WHITE})
CreateBrush(3, 50, 50, #GREEN)
xright = True ; right X
ydown = True ; down Y
speed = 4
LoadBrush
Repeat
oldx = x
oldy = y
;-------------|X|-----------------
If xright = True
If x < windowwidth-95
x = x + speed
Else xright = False
EndIf
Else
If x > -2
x = x - speed
Else xright = True
EndIf
EndIf
;-------------|Y|------------------
If ydown = True
If hidebrush2 = True
MoveBrush(2, -100, -100, -100, -101)
hidebrush2 = False
EndIf
If y < windowheight-75
y = y + speed
Else
ydown = False
hidebrush1 = True ; hide the other brush once when turning
EndIf
MoveBrush(1, oldx, oldy, x, y)
Else
If hidebrush1 = True
MoveBrush(1, -100, -100, -100, -101)
hidebrush1 = False
EndIf
If y > -1
y = y - speed
Else
ydown = True
hidebrush2 = True ; hide the other brush once when turning
EndIf
MoveBrush(2, oldx, oldy, x, y)
EndIf
If IsKeyDown("ESC") Then quit = 1
Until quit = 1