Extended version of TImage..
BlitzMax Forums/BlitzMax Module Tweaks/Extended version of TImage..
| ||
.. which includes some useful functions.Type T_Image Extends TImage Field Pic:TImage Field x:Float = 0 Field oldx:Float Field y:Float = 0 Field oldy:Float Field Scalex:Float = 1 Field Scaley:Float = 1 Field Rotation:Float = 0 Field CurrentSpeedX:Float Field CurrentSpeedY:Float Field Blend:Int = SOLIDBLEND Field Alpha:Float = 1 Field Color:Int [] = [255,255,255] Function LoadMyImage:T_Image (url:Object,Flags:Int = -1) Local Image:T_Image = New T_Image Image.Pic = LoadImage (url,Flags) Return Image End Function Function LoadMyAnimImage:T_Image (url:Object,cell_width:Int,cell_height:Int,first_cell:Int,cell_count:Int,Flags:Int=-1) Local Image:T_Image = New T_Image Image.Pic = LoadAnimImage (url,cell_width,cell_height,first_cell,cell_count,Flags) Return Image End Function Method CopyMyImage:T_Image () Local Image:T_Image = New T_Image Image.Pic = CreateImage (ImageWidth(Pic),ImageHeight(Pic)) Local TmpSrcPic:TPixmap = LockImage(pic) Local TmpDestPic:TPixmap = LockImage(Image.pic) For Local x:Int = 1 To ImageWidth(Pic) For Local y:Int = 1 To ImageHeight(Pic) WritePixel (TmpDestPic,x-1,y-1,ReadPixel(TmpSrcPic,x-1,y-1)) Next Next UnlockImage pic UnlockImage Image.pic Return Image End Method Method MidHandleMyImage () MidHandleImage Pic End Method Method DrawMyImage (Frame:Int = 0) SetRotation Rotation SetScale Scalex,Scaley SetBlend Blend SetColor Color[0],Color[1],Color[2] SetAlpha Alpha DrawImage (Pic,x,y,Frame) SetRotation 0 SetScale 1,1 SetBlend SOLIDBLEND SetColor 255,255,255 SetAlpha 1 End Method Method MoveMyImage (NX:Float,ny:Float,MGlobal:Int = 0) oldx = x oldy = y If MGlobal = 0 SetRotation Rotation x:+ (ny*(Sin(Rotation))) y:- (ny*(Cos(Rotation))) x:+ (NX*(Cos(Rotation))) y:+ (NX*(Sin(Rotation))) Else SetRotation 0 x:+ NX y:+ ny EndIf SetRotation 0 End Method Method PositionMyImage (NX:Float,ny:Float) x = NX y = ny End Method Method TurnMyImage (Angle:Float) Rotation:+ Angle End Method Method RotateMyImage (Angle:Float) Rotation = Angle End Method Method ScaleMyImage (NX:Float,ny:Float) Scalex = NX Scaley = ny End Method Method MyImageBlend (NBlend:Int) Blend = NBlend End Method Method MyImageColor (nr:Int = 255,nv:Int = 255,nb:Int = 255) Color[0] = nr Color[1] = nv Color[2] = nb End Method Method MyImageAlpha (NAlpha:Float = 1) Alpha = NAlpha End Method Method GetMyImagePosX:Float () Return x End Method Method GetMyImagePosY:Float () Return y End Method Method GetMyImageRotation:Float () Return Rotation End Method Method GetMyImageXSpeed:Float () CurrentSpeedX = x-oldx Return CurrentSpeedX End Method Method GetMyImageYSpeed:Float () CurrentSpeedY = y-oldy Return CurrentSpeedY End Method Method GetMyImageDistance:Float (Dx,Dy) Local DistX:Float = (Dx - x)*(Dx - x) Local DistY:Float = (Dy - y)*(Dy - y) Local Distance:Float = DistX + DistY Return Sqr(Distance) End Method End Type |
| ||
If MGlobal = 0 think this would produce the same result, but is faster:SetRotation Rotation x:+ (ny*(Sin(Rotation))) y:- (ny*(Cos(Rotation))) x:+ (NX*(Cos(Rotation))) y:+ (NX*(Sin(Rotation))) Else SetRotation 0 x:+ NX y:+ ny EndIf SetRotation 0 If MGlobal = 0 x:+ (ny*(Sin(Rotation))) y:- (ny*(Cos(Rotation))) x:+ (NX*(Cos(Rotation))) y:+ (NX*(Sin(Rotation))) Else x:+ NX y:+ ny EndIf SetRotation 0 |
| ||
Edit: no sorry |