Objects doesn't appear

local storyboard = require “storyboard”

local scene = storyboard.newScene()

physics = require( “physics” )

physics.start()

physics.setGravity(0, 0) – x , y

function scene:createScene( event )

local group = self.view

– Limites do ecrã

local borderTop = display.newRect( 0, 0, 1000, 1 )

borderTop:setFillColor( 0, 0, 0, 0) – make invisible

physics.addBody( borderTop, “static”, borderBodyElement )

local borderBottom = display.newRect( 0, 707, 1000, 1 )

borderBottom:setFillColor( 0, 0, 0, 0) – make invisible

physics.addBody( borderBottom, “static”, borderBodyElement )

local borderLeft = display.newRect( 0, 1, 1, 707 )

borderLeft:setFillColor( 0, 0, 0, 0) – make invisible

physics.addBody( borderLeft, “static”, borderBodyElement )

local borderRight = display.newRect( 1000, 1, 1, 707 )

borderRight:setFillColor( 0, 0, 0, 0) – make invisible

physics.addBody( borderRight, “static”, borderBodyElement )

end

function scene:enterScene( event )

local group = self.view


–CirculoVermelhoDireita

local myCircle = display.newCircle(40, 40, 30)

local trailprops = {x= 20, y = 20,r = 5} – r= tamanho do circulo do rasto, x e y é para centrar o rasto no meio

physics.addBody (myCircle, “dynamic”, {density=1.0, friction=0.5, bounce=0.0 } )

myCircle:setFillColor ( 255, 0, 0)

myCircle.x = 580

myCircle.y = 435

–Mover circuloVermelho

function myCircle:touch ( event )

if event.phase == “began” then

self.markX = self.x

self.markY = self.y

elseif event.phase == “moved” then

local x = (event.x - event.xStart) + self.markX

local y = (event.y - event.yStart) + self.markY

self.x, self.y = x, y

end

return true

end

myCircle:addEventListener( “touch”, myCircle)

function redraw () – Desenha o rasto

    Trail = display.newCircle( myCircle.x + trailprops.x, myCircle.y + trailprops.y, trailprops.r)

   Trail:setFillColor (255, 0, 0)

      

    myCircle:toFront( )

    print("!")

end

Runtime:addEventListener( “enterFrame”, redraw )

group:insert( myCircle )

group:insert( trailprops )

group:insert( redraw )

group:insert( Trail )

group:insert( Runtime )

end

end

function scene:exitScene( event )

local group = self.view

end

end

function scene:destroyScene( event )

local group = self.view

end


– Listener setup

scene:addEventListener( “createScene”, scene )

scene:addEventListener( “willEnterScene”, scene)

scene:addEventListener( “enterScene”, scene )

scene:addEventListener( “exitScene”, scene )

scene:addEventListener( “destroyScene”, scene )


return scene

Which object doesn’t show? You got to be more specific, is there an error?

“CirculoVermelhoDireita” 

BR? 

No, it’s portuguese.

The red ball (circuloVermelho) doesn’t appear

There’s a few mistakes here. You shouldn’t be inserting stuff like ‘Runtime’, ‘trailprops’ and ‘redraw’ into groups. Only display objects should be inserted.

myCircle cannot be accessed from within redraw because it is local to enterScene. Therefore myCircle:toFront() does nothing. If you want myCircle accessible to all functions, you need to pre-define it at the top of the lua file:

[lua]

local myCircle

— then when you create it

myCircle = display…

[/lua]

You’re also creating a new global trail circle every frame, and never destroying it. This is quickly going to slow your app down to a crawl. Each time a new ‘Trail’ is drawn, the reference to the old one is lost and you’ll have a memory leak, as well as having hundreds of circle objects being drawn on top of myCircle.

group:insert(Trail) will also do nothing because at that point trail does not exist, so all your trail objects will never be cleaned up by storyboard.

I also don’t think trailprops is accessible by redraw because that is also local to enterScene.

Which object doesn’t show? You got to be more specific, is there an error?

“CirculoVermelhoDireita” 

BR? 

No, it’s portuguese.

The red ball (circuloVermelho) doesn’t appear

There’s a few mistakes here. You shouldn’t be inserting stuff like ‘Runtime’, ‘trailprops’ and ‘redraw’ into groups. Only display objects should be inserted.

myCircle cannot be accessed from within redraw because it is local to enterScene. Therefore myCircle:toFront() does nothing. If you want myCircle accessible to all functions, you need to pre-define it at the top of the lua file:

[lua]

local myCircle

— then when you create it

myCircle = display…

[/lua]

You’re also creating a new global trail circle every frame, and never destroying it. This is quickly going to slow your app down to a crawl. Each time a new ‘Trail’ is drawn, the reference to the old one is lost and you’ll have a memory leak, as well as having hundreds of circle objects being drawn on top of myCircle.

group:insert(Trail) will also do nothing because at that point trail does not exist, so all your trail objects will never be cleaned up by storyboard.

I also don’t think trailprops is accessible by redraw because that is also local to enterScene.