Layers and brushes

Find quick help here to get you started with Hollywood
Post Reply
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Layers and brushes

Post by amyren »

I did make a small program with a smiley brush that bounces around in a window.
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
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Layers and brushes

Post by airsoftsoftwair »

AFAIR MoveBrush() will add a layer every time it is called. You can easily check this by calling the DumpLayers() function. If you don't want to have new layers all the time, just add a brush layer using DisplayBrush() and then use MoveLayer() to move that layer.

There is no HideBrush() or RemoveBrush() because that obviously requires layering. Brushes are just a container for graphics and they have no layering mechanism built in them. For this you need to enable layers.
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: Layers and brushes

Post by amyren »

Thanks. I did test with DumpLayers(), and it does look like the layer is created only first time the brush is displayed. Next time MoveBrush() is called there will not be a new layer.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Layers and brushes

Post by airsoftsoftwair »

Right, if the object is already there, it will be "picked up" by MoveBrush().
Post Reply