How can I apply two effectes to the same brush?

Discuss any general programming issues here
Post Reply
ilbarbax
Posts: 82
Joined: Thu Apr 01, 2010 6:41 pm

How can I apply two effectes to the same brush?

Post by ilbarbax » Sun Oct 24, 2010 4:38 pm

I want to scroll a brush trough the screen with MoveBrush command but at the same brush during the movemt I would like to apply an effect of transpareny change How could be possible?

jalih
Posts: 247
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: How can I apply two effectes to the same brush?

Post by jalih » Sun Oct 24, 2010 6:25 pm

I think with MoveBrush(), you are out of luck.

You have a couple of other options available though:

Use layers:
- take a look at AddMove(), DoMove() and ClearMove() functions
- you can modify layer attributes (scaling, rotation, transparency, tint-color, etc) with SetLayerStyle() function

Use double buffer:
- just use DisplayBrush() to draw and a simple loop to change the drawing position
- controlled transparency effects can be applied with using SelectAlphaChannel(), SetAlphaIntensity() and drawing to alpha channel of a brush. After drawing remember to call EndSelect.

jalih
Posts: 247
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: How can I apply two effectes to the same brush?

Post by jalih » Sun Oct 24, 2010 9:27 pm

Simple layer example:

Code: Select all

@DISPLAY {Width = 640, Height = 480, Title = "Simple Layer test"}

EnableLayers
SetFillStyle(#FILLCOLOR)
Box(#CENTER, #CENTER, 300, 200, #RED, {Name = "HelloBox", AnchorX = 0.5, AnchorY = 0.5, RoundLevel = 25, Hidden = True })
SelectLayer("HelloBox")
SetFont(#SANS, 50)
SetFontStyle(#ANTIALIAS)
TextOut(#CENTER, #CENTER, "Hello World!")
EndSelect

ShowLayer("HelloBox", #CENTER, #TOPOUT)

ang = 0
transp = 0
dtransp = 2
y = -200

Repeat
	y = y + 2
	y = Wrap(y, -200, 680)
	ang = ang + 2
	ang = Wrap(ang, 0, 360)
	transp = transp + dtransp
	If transp >= 255 Or transp <= 0 Then dtransp = -dtransp

	SetLayerStyle("HelloBox", {Y = y, Rotate = ang, Transparency = transp})   
Forever

jalih
Posts: 247
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: How can I apply two effectes to the same brush?

Post by jalih » Sun Oct 24, 2010 10:00 pm

Here is, how to do transparency effects using alpha channel (simple light effect):

Just replace BRUSH 4, "hertta.png" with some 800x600 sized png image of your own.

Code: Select all

@VERSION 2,0    /* Hollywood 2.0 strictly required */

/*
** External data
*/

@BRUSH 4, "hertta.png"


@DISPLAY {Width = 800, Height = 600}

Function p_MainLoop()
	Local mx = MouseX()
	Local my = MouseY()
	
	SelectAlphaChannel(10)
	SetAlphaIntensity(255)
	Cls
	SetAlphaIntensity(0)
	Circle(mx-250, my-250, 250)
	EndSelect

	DisplayBrush(4, #CENTER, #CENTER)
	DisplayBrush(10, #CENTER, #CENTER)	
	
	DisplayBrush(5, mx - 250 , my - 250)
	
	Flip
	
EndFunction



SetFillStyle(#FILLCOLOR)
CreateBrush(3, 100, 100)
SelectBrush(3)
Circle(0, 0, 50, #WHITE)
EndSelect

SelectAlphaChannel(3)
SetAlphaIntensity(0)
Cls

i = 0

For k = 51 To 1 Step -1
	Circle(#CENTER, #CENTER, k)
	SetAlphaIntensity(i)
	i = i + 5
Next

EndSelect

CopyBrush(3, 5)
ScaleBrush(5, 500, 500, True) 

CreateBrush(10, 800, 600)

/* LeftMouseQuit(True) */
EscapeQuit(True)

SetInterval(1, p_MainLoop, 1000/25) ; 25fps

BeginDoubleBuffer


Repeat
	WaitEvent
Forever

ilbarbax
Posts: 82
Joined: Thu Apr 01, 2010 6:41 pm

Re: How can I apply two effectes to the same brush?

Post by ilbarbax » Tue Oct 26, 2010 11:01 am

Thanks, I will have a try this weekend

Post Reply