Game Development Reference
In-Depth Information
Filled Shapes
Gideros Studio allows for filling shapes with either a solid color or an image. This can help for some
interesting results like creating an image mask or seamlessly filled textures. Here's some example
code for filling a shape with an image:
local texture = Texture.new("image.png") setFillStyle(Shape.TEXTURE, texture)
-- Sets the fill style as texture with "image.png"
We can use this to create a rectangle filled with a texture, handy for creating tiled backgrounds and
such. Figure 9-14 shows an example.
function newImgRectangle(x1, y1, x2, y2, lw, lc, imgName)
local obj = Shape.new()
-- The image for the fill
local img = Texture.new(imgName)
local lw = lw or 1
local lc = lc or 0x000000
local wd, ht = x2-x1, y2-y1
obj:clear()
obj:setLineStyle(lw, lc)
obj:setFillStyle(Shape.TEXTURE, img)
obj:beginPath()
obj:moveTo(0,0)
obj:lineTo(0, ht)
obj:lineTo(wd, ht)
obj:lineTo(wd,0)
obj:lineTo(0,0)
obj:closePath()
obj:endPath()
obj:setPosition(x1, y1)
stage:addChild(obj)
return obj
end
newImgRectangle(10, 10, 70, 70, 0, nil, "myImage2.png")
 
Search WWH ::




Custom Search