Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Sprite/Drawing Functions

Author
Message
Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 26th Feb 2012 23:51 Edited at: 26th Feb 2012 23:55
Hi,

This time I came up with something more practical - using sprites to draw stuff. I tried to replace some 2D drawing commands available in DBP (particularly line and box) with sprite-based functions that allow alpha blending and may be faster (I'm not sure about the speed of drawing commands with DBPs latest version, I haven't updated in quite a while, hence the line command is really slow for me).

It is really nothing spectacular (and there are most certainly plugins available doing the job more efficiently), but is indeed useful for myself, so I thought I'd just share it here.

The functions should be rather self-explanatory, but anyway, here's the command set:

General:
spr_init() - should be called once in the beginning
spr_prepareMedia() - usually does not need to be called, but may be useful when the media has to be reloaded (happens sometimes when leaving the window and opening it again, as far as I know)

Sprite Based:
SpriteID = spr_make(img) - receives an image and builds a hidden sprite out of it that can be pasted later
SpriteID = spr_load(file$) - loads an image and returns it as sprite
SpriteID = spr_loadAni(file$,tilesX,tilesY) - loads an animated sprite
spr_Offset(ID, fx#, fy#) - offsets the sprite relative to its size
spr_Center(ID) - equal to spr_Offset(ID, 0.5, 0.5) to rotate a sprite around its center

Primitive Drawing:
spr_SetColor(r,g,b,a) - sets the color used for Box, Frame and Line
spr_Box(x1,y1,x2,y2) - draws a box using the color defined with spr_SetColor()
spr_Frame(x1,y1,x2,y2) - draws a frame
spr_ThickFrame(x1,y1,x2,y2,thickness) - draws a thick frame (thickness defined in pixels)[/b]
spr_Line(x1,y1,x2,y2) - draws a line
spr_ThickLine(x1,y1,x2,y2,thickness) - draws a thick line

spr_SetTriangleColor(r,g,b,a) - sets the color used for drawing triangles
spr_Triangle(x,y,angle,w,h) - draws a triangle at the given position with the given angle (note: kind of rotation can be changed inside this function) and size


Once again, thanks for your interest and have fun with it.



Code with example:



noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 28th Feb 2012 20:32
again nice work

but, as with the free list thing, alpha blending and more is already supported with an AWESOME dll that i use in about all my projects called adnvanced2d. it supports all the blending ops that you ever might need ( also a lot that you never will )

but nice! keep it coming
Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 28th Feb 2012 20:53
Quote: "alpha blending and more is already supported with an AWESOME dll that i use in about all my projects called adnvanced2d"


I have to admid I've never heared of it (as far as I remember), but I'll check it out, thank you.

Login to post a reply

Server time is: 2024-04-18 11:48:24
Your offset time is: 2024-04-18 11:48:24