Max2D Module Needs some changes :P

BlitzMax Forums/BlitzMax Module Tweaks/Max2D Module Needs some changes :P

FBEpyon(Posted 2005) [#1]
I was playing around with the blitzmax 2d module today, and the alphablend is sweet, but having to defind it everytime is a pain can someone by change make a new set of mods that make a function like this:

Drawimage_Alpha ( Image$, x, y, Frame=0, Alpha=0 )

I have tried but failed like no other :(


tonyg(Posted 2005) [#2]
Somebody suggested this before...
HERE


altitudems(Posted 2005) [#3]
And here is a helper function if you like:
Function DrawSprite(_Image:TImage, _X:Float, _Y:Float, _Alpha:Float=-1, _Frame:Int = -1)
	Local tAlpha:Float, tMode:Int
		
	tMode	= GetBlend ()
	tAlpha	= GetAlpha ()

	If _Mode <> ALPHABLEND Then SetBlend ALPHABLEND
	If _Alpha <> -1 Then SetAlpha _Alpha		
	If _Frame = -1 Then _Frame = 0

	DrawImage _Image, _X, _Y, _Frame
		 		
	SetAlpha tAlpha
	SetBlend tMode
End Function



altitudems(Posted 2005) [#4]
Here is something that might be useful to you as well:
Strict

Global SpriteList:TList = CreateList()

Type tSprite
	Field Image:TImage
	Field Mode:Int
	Field ScaleX:Float
	Field ScaleY:Float
	Field Angle:Float
	Field Alpha:Float
	Field Tint:Int [3]

	Function Create:tSprite (_Image:TImage, _Mode:Int = ALPHABLEND)
		Local o:tSprite = New tSprite
			o.Image	= _Image
			o.Mode	= ALPHABLEND
			o.ScaleX= 1.0
			o.ScaleY= 1.0
			o.Angle	= 0.0
			o.Alpha	= 1.0
			o.Tint	= [255,255,255]
		SpriteList.AddLast(o)
		Return o
	End Function

	Method Render (_X:Float, _Y:Float, _Frame:Int = -1)
		Local _ScaleX:Float, _ScaleY:Float, _Angle:Float
		Local _Alpha:Float, _Mode:Int, _Tint:Int [3]
		
		_Angle	= GetRotation ()
		_Alpha	= GetAlpha ()
		_Mode	= GetBlend ()
		GetScale _ScaleX,_ScaleY
		GetColor _Tint[0],_Tint[1],_Tint[2]
		
		SetScale ScaleX, ScaleY 		
		SetRotation Angle
		SetAlpha Alpha
		SetBlend Mode
		SetColor Tint[0], Tint[1], Tint[2]

		If _Frame = -1 Then _Frame = 0
		DrawImage Image, _X, _Y, _Frame
		 		
		SetScale _ScaleX, _ScaleY 		
		SetRotation _Angle
		SetAlpha _Alpha
		SetBlend _Mode
		SetColor Tint[0], Tint[1], Tint[2]
	End Method
End Type
So your game code could look like this:
Graphics 800,600,0
Local MyImage:TImage = LoadImage("image.png")

Local MySprite:tSprite = tSprite.Create(MyImage)
MySprite.Alpha = .8
MySprite.Angle = 90
MySprite.ScaleX = .5
MySprite.ScaleY = .5
MySprite.Tint = [255,128,0]

While Not KeyHit(KEY_ESCAPE)
	Cls
	MySprite.Render(MouseX(), MouseY())
	Flip
	FlushMem
Wend