animation movement help

I am currently working on animating an enemy. While i have the animation working, I need it moving and it is not. I don’t know why. Here is the code: any help would be great, thanks! [code] – tank animation
local sheet1 = sprite.newSpriteSheet( “tank_sprite_sheet.png”, 75, 125)

local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 5)
sprite.add( spriteSet1, “tank”, 1, 5, 1000, 0 ) – plays non shooting frames every 1000 ms

local instance1 = sprite.newSprite( spriteSet1 )
instance1.x = display.contentWidth / 75
instance1.y = 125
–instance1.xScale = .5
–instance1.yScale = .5

instance1:prepare(“tank”)
instance1:play()

– A per-frame event to move the elements
local tPrevious = system.getTimer()
local function move(event)
local tDelta = event.time - tPrevious
tPrevious = event.time

–if (grass.x + grass.contentWidth) < 0 then
– grass:translate( 480 * 2, 0)
–end

tank = {}

for i = 1, #tank, 1 do
tank[i].x = tank[i].x - tank[i].dx * tDelta * 0.2
if (tank[i].x + tank[i].contentWidth) < 0 then
tank[i]:translate( 480 + tank[i].contentWidth * 2, 0 )
end
end
end
[import]uid: 94237 topic_id: 21559 reply_id: 321559[/import]

Where are your tanks? I see you doing tank = {} but not actually adding any tanks to it. [import]uid: 52491 topic_id: 21559 reply_id: 85465[/import]

is that why it is animating but not moving then? because no tanks are being added? [import]uid: 94237 topic_id: 21559 reply_id: 85703[/import]

Your code is written to move tanks, however many tanks you have in the tank table - but the table is empty so there is nothing to move. [import]uid: 52491 topic_id: 21559 reply_id: 85747[/import]

ah ok, i see what you mean. thanks! [import]uid: 94237 topic_id: 21559 reply_id: 85955[/import]

the table has been scraped now, we are trying to call the start point and move the tank from the same function but it is not cooperating. Half the time is says setStartPoint is a nil value and half the time it says instance1 is a nil value in the rotation line. [code] local function tank(event)

– tank animation
local sheet1 = sprite.newSpriteSheet( “tank_sprite_sheet.png”, 75, 125)

local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 5)
sprite.add( spriteSet1, “tank”, 1, 5, 1000, 0 ) – plays non shooting frames every 1000 ms

function setStartPoint(x, y)

local instance1 = sprite.newSprite( spriteSet1 )
instance1.x = x
instance1.y = y + 5

–instance1.xScale = .5
–instance1.yScale = .5

–instance1.x = x
–instance1.y = y
–end

local tank = instance1.rotation
instance1.rotation = 90
end
instance1:prepare(“tank”)
instance1:play()
end

–if(self.x = rich.x)
–fire cannon
–if(self.x > rich.x) or (self.x < rich.x)
–then instance1.x + 5 until = rich.x
–end

Runtime:addEventListener(“enterFrame”, tank)
[import]uid: 94237 topic_id: 21559 reply_id: 86794[/import]

someone else who uses a mac tried it out and had no errors but the tank was not moving as well. [import]uid: 94237 topic_id: 21559 reply_id: 86806[/import]

You have two things called “tank”, a function and an object, you may want to remedy that :slight_smile: [import]uid: 52491 topic_id: 21559 reply_id: 86823[/import]

i changed the name of the function and that fixed part of it but now it is saying that instance1 is a nil value on instance1:prepare(tank) line [import]uid: 94237 topic_id: 21559 reply_id: 87130[/import]

Take a look at the sample code located;
CoronaSDK > SampleCode > Sprites > JungleScene

If you do that and can’t modify it for your sprite, post code again, with all current changes, and I can try to advise further.

Peach :slight_smile: [import]uid: 52491 topic_id: 21559 reply_id: 87241[/import]

my code is similar to that but that code is not in a function, here is my current code. [code] module(…, package.seeall)
require “sprite”
local function tankmove(event)

– tank animation
local sheet1 = sprite.newSpriteSheet( “tank_sprite_sheet.png”, 75, 125)

local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 5)
sprite.add( spriteSet1, “tank”, 1, 5, 1000, 0 ) – plays non shooting frames every 1000 ms

function setStartPoint(x, y)

local instance1 = sprite.newSprite( spriteSet1 )
instance1.x = x
instance1.y = y + 5

–instance1.xScale = .5
–instance1.yScale = .5

–instance1.x = x
–instance1.y = y
–end

local tank = instance1.rotation
instance1.rotation = 90
end
instance1:prepare(“tank”)
instance1:play()
end

–if(self.x = rich.x)
–fire cannon
–if(self.x > rich.x) or (self.x < rich.x)
–then instance1.x + 5 until = rich.x
–end

Runtime:addEventListener(“enterFrame”, tankmove) [import]uid: 94237 topic_id: 21559 reply_id: 87604[/import]

Why is this tied to a Runtime listener?

Can you move everything there that doesn’t need to be within that function outside of it? I expect that is causing the error.

OOI, what part of that function are you trying to use every frame? Might have some advise there also.

Peach :slight_smile: [import]uid: 52491 topic_id: 21559 reply_id: 87639[/import]

the instance, lines 17-19 and 32 and 33 are also relevant. Those are what need to be checked every frame for movement. I thought connecting a listener to the function would work but its only partially working. Maybe runtime was the wrong kind of listener to use? [import]uid: 94237 topic_id: 21559 reply_id: 88133[/import]

i took function off of set start point where then it was saying that set start point was a nil value. I think the listener should be set to check the setstartpoint function. [import]uid: 94237 topic_id: 21559 reply_id: 88220[/import]

i think i’m close, it said assertion failed. thats all it said though. I’m not sure what that means [import]uid: 94237 topic_id: 21559 reply_id: 88221[/import]

The code above isn’t calling setStartPoint, it’s just reloading the sprite every frame, when it only needs to be loaded one time.

Without seeing the setStartPoint being called it is hard to know quite what is happening, how, when, etc. [import]uid: 52491 topic_id: 21559 reply_id: 88267[/import]

right so it needs to call the setStartPoint. what should be put in the listener? x,y? That is what i tried and it said assertion failed. [import]uid: 94237 topic_id: 21559 reply_id: 88270[/import]

setStartPoint(10,10)

With 10, 10 being the X and Y you want to use. [import]uid: 52491 topic_id: 21559 reply_id: 88317[/import]

should the setStartPoint be in the listener as well? [import]uid: 94237 topic_id: 21559 reply_id: 88430[/import]

with x,y it said assertion failed and when i put in 10,10 it was expecting a name. I have it calling the setStartPoint function now. [import]uid: 94237 topic_id: 21559 reply_id: 88545[/import]