This is a class which represents 32bit bitmap with 8 bitmap alpha channel.
Star Ruby supports only PNG format file. It supports alpha channel too.
Class methods
Texture.load(path)-
Load an image file into a texture. File extension can be omitted.
Texture.new(width, height)-
Make a texture of certain size. All pixels RGBA set as
StarRuby::Color.new(0, 0, 0, 0). Texture.transform_in_perspective(x, y, height, options = {})-
(It is recommended not to use since ver 0.2.0. Please use
Texture#transform_in_perspectivemethod instead.)Get position and scale of an object at position(
x,y) withheightafter you applied perspective transformation to it.Return value is an array [(X-coordinate), (Y-coordinate), (scale)]. X coordinate and Y coordinate will be
Fixnum, scale will beFloorvalue. If coordinates exceeds range ofFixnum, those will benil. So when you use this method, you should check whether all return values are notnil. Return scale can be negative.You need to set
Hashforoptions. ReferTexture#render_in_perspectivemethod for a list of selectable keys and values.
Instance methods
[](x, y)[]=(x, y, color)-
Get the color of a pixel at (
x,y).Different from
render_pixel, this method does not take color of target texture into consideration. change_hue(d_hue)change_hue!(d_hue)-
change_huemethod will generate new texture and return it.change_hue!It is a destructive methodd_huemust be set as radian. when the value is 0, the hue will not be changed.This transformation is irreversible. Be warned that there are minor inaccuracies.
(Before ver 0.1.5, change_hue was a destructive method.)
clear-
Clear all pixels. Equal as
fill(Color.new(0, 0, 0, 0)). clonedup-
Returns a clone of this texture.
dispose-
Release the resource of this texture.
disposed?-
If the resource has been already disposed by
dispose, returntrue, otherwise returnfalse. dump(format)-
Dump image data. return
Stringobject which represents byte of the image. The length of returnStringobject will be "texture width * texture height * length of the format".formatis constructed by at least one character from the list below.Argument Meaning rRed component gGreen component bBlue component aAlpha component For example if you set
formatas"rgba", return value will be aString" object where "red, green, blue, alpha" are ordered repeatedly for each pixel.The order of pixel is left to right, up to down.
Please refer
undumptoo. fill(color)-
Fill this texture with a chosen
color(Color). fill_rect(x, y, width, height, color)-
Fill this texture with a chosen color,
color(Color) in rectangular shape.Unlike
render_rectmethod, color of target texture will be ignored. get_pixel(x, y)-
(It is recommended not to use since ver 0.2.0. Please use
[]method instead.)Get the color of a pixel at (
x,y). height-
Get height of this texture.
render_in_perspective(texture, options = {})-
Execute perspective projection rendering.
selfas the screen,texturein arguments as an image of the ground.As
options, you need to passHash. Keys and values below can be selected.Key Value Default :camera_x/:camera_yCamera's position. Origin is the top left of texture.0 :camera_angle(It is recommended not to use since ver 0.1.13. Please use :camera_yawinstead.) Camera's angle.0 :camera_heightCamera's height from the ground. Negative value is also valid. If it is 0, nothing will be rendered. 0 :camera_yaw/:camera_pitch/:camera_rollRespectively cameras yaw, pitch and roll. 0 :distance(It is recommended not to use after Ver 0.2.0. Please use :view_angleinstead.) Distance between the camera and the screen.0 :intersection_x/:intersection_yIntersect point of the camera ray and the screen. Origin is top left of the screen( self).0 :vanishing_x/:vanishing_y(It is recommended not to use after Ver 0.1.13. Please use :intersection_x/:intersection_yinstead.) The position of vanishing point. Origin is top right of the screen(self).0 :view_angleView angle (0 to π). π / 4 :loopRender looped texture or not. falsePlease refer
Texture#transform_in_perspectivemethod too. render_line(x1, y1, x2, y2, color)-
Draw a line from (
x1,y1) to (x2,y2) with selectedcolor. render_pixel(x, y, color)-
Put a pixel of
colorat coordinate (x,y).Different from
[]=, it takes color of target texture into consideration. render_rect(x, y, width, height, color)-
Render a rectangle on a texture in color passed in
color(Color).Different from
flll_rect, it takes color of target texture into consideration. render_text(text, x, y, font, color, anti_alias = false)-
Render
textas text at coordinate (x,y)For
fontyou pass an instance ofFontwhich represents font of the text. Forcoloryou pass an instance ofColor. Foranti_alias, pass whether or not to anti-alias the text. render_texture(texture, x, y, options = {})-
Render
textureat position (x,y)You can set
selfastexturetoo.(In that caseselfwill be copied inside this method.(Alpha Blending rule will be written later.)
Bigger alpha value for each pixel of render target (
self) and this texture will be used.As
options, you need to passHash. Keys and values below can be selected.Key Value Default :alphaOpaque(0 - 255). 255 :angleRotation radian. 0 :blend_typeType of blending. :alphais standard alpha blending,:addis addition,:subis substraction. If:nonewas chosen, ignore the render target pixels. (Since ver 0.1.16)。:alpha:center_x/:center_ycenter point (in pixel) of geometry transform. Origin is the left top of texture.0 :saturationSaturation(0 - 255). 0 means complete monochrome. 255 :scale_x/:scale_yScale of x and y axis. If negative value was passed, texturewill be rendered reversed.1 :src_width/:src_heightSource area's width and height of texture.Values after texture's width and height are subtracted by:src_x,:src_y:src_x/:src_yX, Y coordinates of texture0 :tone_red/:tone_green/:tone_blueComponents of hue transformation (-255 - 255). Negative values weaken that component and positive values strengthen the component. 0 Geometry transformation will be processed in order below.
- Scale the
texture:center_x,:center_yas center. - Rotate the
texture:center_x,:center_yas center. - Translate the
texture for (x,y).
Color transformation will be processed in order below.
- Saturation transformation will be done by the value of
:saturation. - Color transformation will be done by the values of
:tone_red/:tone_green/:tone_blue.
- Scale the
save(path, alpha = true)-
Save the texture to
pathas PNG. Ifalphameans a value of false, ignores alpha value. set_pixel(x, y, color)-
(It is recommended not to use since ver 0.2.0. Please use
[]=method instead.)Put color (
Color) of pixel at (x,y).Different from
render_pixel, this method does not take color of target texture into consideration. size-
Return array of texture size ([(width), (height)]).
transform_in_perspective(x, y, height, options = {})-
Get position and scale of an object at position(
x,y) withheightafter you applied perspective transformation to it.Return value is an array [(X-coordinate), (Y-coordinate), (scale)]. X coordinate and Y coordinate will be
Fixnum, scale will beFloorvalue. If coordinates exceeds range ofFixnum, those will benil. So when you use this method, you should check whether all return values are notnil. Return scale can be negative.You need to set
Hashforoptions. ReferTexture#render_in_perspectivemethod for a list of selectable keys and values. undump(data, format)-
ApplyfollowingStringobject specified in dataformat.Refer
dumpabout format ofdataandformat.Data length must be exactly the same as "texture height * texture width * format length"
width-
Get texture width.