transition.to used with a sprite sheet

Hi,
I am trying to move an animated character (sprite). The aim is to have it walking but when I use transition.to the sprite moves BUT it also doubles up (two images of the same sprite slightly shifted). The faster the animated character moves the bigger is the shift of what appears to be like the same sprite loaded twice…
What am I doing wrong. I have a touch event that start the walk and I tried to put a delay in order to avoid the problem but the sprite is clean when on delay, but shift again as soon as it start travelling…

many thanks

pollen [import]uid: 8464 topic_id: 3707 reply_id: 303707[/import]

Will need to see some code to find the issue. [import]uid: 11024 topic_id: 3707 reply_id: 11282[/import]

Ok Finnk,

here is the code

require"sprite"
local background = display.newImage( “background.png” )
local textObject = display.newText ( “WELCOME”, 115, 200, nil, 24 )
local textObject1 = display.newText ( " TROGS", 80, 300, nil, 48 )
local textObject2 = display.newText ( “to”, 160, 250, nil, 24 )
textObject:setTextColor (255,255,255)
textObject1:setTextColor (255,255,255)
textObject2:setTextColor (255,255,255)

local data = require (“trogwalk”).getSpriteSheetData()
local sheet = sprite.newSpriteSheetFromData(“trogwalk.png”, data)
local set = sprite.newSpriteSet (sheet, 1, 12)

–[[local function spriteEvent(pEvent)
if pEvent.phase == “loop” then
pEvent.sprite:removeEventListener(“sprite”, spriteEvent)
pEvent.sprite:removeSelf()
end
end–]]
local function touchEvent(pEvent)
local instance = sprite.newSprite(set)
instance.x = pEvent.x
transition.to (instance, { delay= 200, time=8000, x=instance.x+350 } )
instance.y = pEvent.y
instance:play()
instance:addEventListener(“sprite”, spriteEvent)
end

Runtime:addEventListener (“touch”, touchEvent)

[import]uid: 8464 topic_id: 3707 reply_id: 11284[/import]

Instead of recreating the sprite on each update, why don’t you try reinserting the sprite using a display group to redraw it instead. I think the problem with duplicates come from multiple instances (and transform.tos) of the sprite being made. [import]uid: 11024 topic_id: 3707 reply_id: 11287[/import]

Ok it sounds pretty much chinese to me, since I am a beginner…
I started from the sprite tutorial as you can probably guess from the code and I was wondering if this is the right way to go in the first place…meaning:
if I want to move an animated character walking around a a touch input is this the right way to go or should I study something else?
I am totally new to programming and my background is design so I go through intuition and attempts
(trying to learn lua in the meantime)
I do not know if I make sense…

thanks pollen [import]uid: 8464 topic_id: 3707 reply_id: 11289[/import]

I do not know if it helps…this is the terminal:

The file sandbox for this project is located at the following folder:
(/Users/andrea/Library/Application Support/Corona Simulator/test-animation1 (welcome to Trogs)-0CD70086D6BC92866AF86903716ED299)
Runtime error
assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
…S (game)/test-animation1 (welcome to Trogs)/main.lua:28: in function <…s to trogs>
?: in function <?:214>
Runtime error
assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
…S (game)/test-animation1 (welcome to Trogs)/main.lua:28: in function <…s to trogs>
?: in function <?:214>

[import]uid: 8464 topic_id: 3707 reply_id: 11291[/import] </…s></…s>

Hey Pollen.

No problem. I’m no stranger to cut-and-paste development myself. Along the way you might eventually start having issues with putting it all together even though individual parts work.

I think the best place to start is game architecture. I suggest downloading the Corona Game Template by Ziray Studio Labs to see a decent example of how to organize the code and divide tasks. Just take your time with it and recreate it piece by piece.

Next, I’d look up event-driven programming. See this thread.

Also, it’s worth checking out the Code Exchange. [import]uid: 11024 topic_id: 3707 reply_id: 11295[/import]