I’m am having a slight problem with my code that I have here. What I am trying to accomplish here is a loop of animation. First animation boy holds up ball when user touches word ball. Second animation boy throws ball when word throw is touched. Third is where I am having an issue. I have a .png image of a ball transitioning from the right side of the screen. on completion I want the ball to remove itself because an animation of a boy catching the ball plays when the ball comes back. Heres my code that I got so far [lua]display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR
wordArray = {}
local i = 1
local loqsprite = require(‘loq_sprite’)
local screenW = display.contentWidth
local screenH = display.contentHeight
local BG = display.newImageRect(“background.png”, 1024, 768)
BG.x = screenW/2; BG.y = screenH/2
local words = { “Ball”,“Throw”, “catch”, “Bounce”, “Fall”}
local listener
local bfactory = loqsprite.newFactory(“boy”)
local boy = bfactory:newSpriteGroup()
boy.x = 600; boy.y = 430
boy:prepare(“aniBoy ball”)
local ballfactory = loqsprite.newFactory(“ball”)
local ball = ballfactory:newSpriteGroup()
ball.x = 830; ball.y = 550
ball:play(“aniBall ball”)
ball.alpha = 0
function throwBall (event)
ball.alpha = 1
ball.x = 830; ball.y = 550
transition.to( ball, { time=1000, x = 3200 } )
end
function bounceBall(event)
ball:prepare(“aniBall bounce”)
ball.x = 830; ball.y = 550
ball:play(“aniBall bounce”)
end
function boyBounce ()
boy:play(“aniBoy throw”)
timer.performWithDelay(500, bounceBall, 1 )
end
function catchBall (event)
boy:play(“aniBoy catch”)
end
local function removeBall( _t)
_t:removeSelf()
_t = nil
end
function throwBack ()
transition.to( ball, { time=1000, x = 850, y = 600, onComplete=removeBall})
timer.performWithDelay(500, catchBall, 1 )
end
function boyThrow ()
boy:play(“aniBoy throw”)
timer.performWithDelay(500, throwBall, 1 )
end
atrace(xinspect(ball:getSpriteNames()))
atrace(xinspect(boy:getSpriteNames()))
listener = function( event )
local phase = event.phase
local word = event.target
if ( phase == “ended” ) then
local function complete()
word.alpha = 0.5
local newIndex = (word.index % #words)+1
words[newIndex].alpha = 1
word:removeEventListener( “touch”, listener )
words[newIndex]:addEventListener( “touch”, listener )
end
– delay new word highlight if needed
timer.performWithDelay ( 100, complete )
– animations
if word.index == 1 then boy:play(“aniBoy ball”)
elseif word.index == 2 then boyThrow ()
elseif word.index == 3 then throwBack ()
elseif word.index == 4 then boyBounce ()
end
end
end
– draw words
for i=1,#words do
local word = display.newText ( words[i], 222, 222, native.systemFont, 46)
word.x, word.y = 120, 120 * i
word:setTextColor( 255,0,0 )
word.index = i
words[i] = word
word.alpha = 0.5
end
words[1].alpha = 1
words[1]:addEventListener( “touch”, listener )[/lua]
I am getting this error Runtime error
…9GNQo1k+++TI/-Tmp-/TemporaryItems/372/loq_sprite.lua:320: attempt to call method ‘removeSelf’ (a nil value)
stack traceback:
[C]: in function ‘removeSelf’
…9GNQo1k+++TI/-Tmp-/TemporaryItems/372/loq_sprite.lua:320: in function ‘prepare’
…ZS-a189GNQo1k+++TI/-Tmp-/TemporaryItems/372/main.lua:36: in function ‘_listener’
?: in function <?:446>
?: in function <?:215>
Can any buddy please help me
thanks
[import]uid: 51459 topic_id: 15786 reply_id: 315786[/import]
[import]uid: 52491 topic_id: 15786 reply_id: 58346[/import]
Will pass on your greetings.