Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to show Mesh? — Gideros Forum

How to show Mesh?

ArtiomArtiom Member
edited July 2013 in General questions
Hello,
I have a some trouble with Mesh, can't figure out how to show it.
My code:

local screenOffsetX = application:getLogicalTranslateX() / application:getLogicalScaleX()
local screenOffsetY = application:getLogicalTranslateY() / application:getLogicalScaleY()

local backgroundMesh = Mesh.new()

backgroundMesh:setVertex(1, 0 - screenOffsetX, 0 - screenOffsetY)
backgroundMesh:setVertex(2, application:getLogicalWidth() - screenOffsetX, 0 - screenOffsetY)
backgroundMesh:setVertex(3, application:getLogicalWidth() - screenOffsetX, application:getLogicalHeight() - screenOffsetY)

backgroundMesh:setColor(1, 0x127ef8)
backgroundMesh:setColor(2, 0x127ef8)
backgroundMesh:setColor(3, 0x127ef8)

stage:addChildAt(backgroundMesh, 1)

I can't see anything, what I'm doing wrong?
Thank you

Likes: dr_max

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @Artiom only thing you need to add is to set the index array
    backgroundMesh:setIndexArray(1,2,3)
  • ArtiomArtiom Member
    edited July 2013
    Oh.. thank you, that works :)
  • ArtiomArtiom Member
    Mesh can be only triangle? Can I make quad?
  • ar2rsawseenar2rsawseen Maintainer
    :)
    Unfortunately no, thats is the limitation of the Mesh, that it can only be draw in triangles, thus you will need a triangulation algorithm to draw complex shapes.
    For rectangle you would need two triangles.
    local w, h = application:getContentWidth(), application:getContentHeight()
     
    	-- ------------------------------------------
    	-- Create Mesh
    	-- ------------------------------------------
     
    	-- Create a new mesh object
    	local mesh = Mesh.new()
     
    	-- set Vertices
    	mesh:setVertices(
                                    1, w*.25, h*.25,
    				2, w*.75, h*.25,
    				3, w*.75, h*.75,
    				4, w*.25, h*.75					
    			         )
     
    	-- set Indices
    	mesh:setIndexArray(	
                                    1, 2, 3,
    				1, 3, 4
    				)
     
    	-- set Colors
    	mesh:setColorArray(
    				0x000000, 1, 0x000000, 1,
    				0x00FFFF, 1, 0x00FFFF, 1						
    				)
     
    	-- get bounds
    	local x, y, w, h = mesh:getBounds(mesh)
     
    	-- create mesh-parent-stage hierarchy
    	local parent = Sprite.new()
    	parent:addChild(mesh)
    	stage:addChild(parent)
     
    	-- calculate the center
    	local cx = x + w / 2
    	local cy = y + h / 2
     
    	-- set the center
    	parent:setPosition(cx, cy)
    	mesh:setPosition(-cx, -cy)
Sign In or Register to comment.