How to move a character left

character = display.newSprite(sheet\_movingZombie, sequences\_movingZombie) local sheetOptions { width: 10, --of each individual frame height: 20, --of each individual frame numFrames: 5, --number of total frames in the image sheet sheetContentWidth: 8, --of the entire image sheet sheetContentHeight: 10 --of the entire image sheet } --For example, if you have an images sheet with 5 frames, that has a width of 1000, and height of 200 local exampleSheetOptions { width: 200, height: 200, numFrames: 5, sheetContentWidth: 1000, sheetContentHeight: 200 }

That’s everything I have and I’m getting this error :

41:unexpected symbol near '{'

Line 41 :

local sheetOptions {

I just updated my code but i’m still getting the same error :

character = display.newSprite(sheet\_movingZombie, sequences\_movingZombie) local options { width: 200, height: 200, numFrames: 5, sheetContentWidth: 1000, sheetContentHeight: 200 }

The colons are incorrect, it should be width = 200, height = 200 etc etc

local character = display.newSprite(sheet\_movingZombie, sequences\_movingZombie) local sheetOptions { width = 200, height = 200, numFrames = 5, sheetContentWidth = 1000, sheetContentHeight = 200 }

Still getting the same error 

Also missing an ‘=’ after sheetOptions.

Now I get this error :

game.lua:39: bad argument #1 to 'newSprite' (ImageSheet expected, got nil)

Line 39 : local character = display.newSprite(sheet\_movingZombie, sequences\_movingZombie)

You need to read the sprite documentation from start to finish, and implement it one line at a time. 

Copying and pasting sections of code in from here, into seemingly random places, isn’t going to work.

For example, your sheetOptions table is doing nothing there, coming after you’re trying to create the sprite. That needs to be run before the newImageSheet command and passed in as the second argument. 

I just went through these docs

 https://docs.coronalabs.com/api/library/graphics/newImageSheet.html

 https://docs.coronalabs.com/api/library/display/newSprite.html 

https://docs.coronalabs.com/guide/media/spriteAnimation/index.html#sequences

and I only got the image showing and it’s barely on the screen . It doesn’t move or anything . It’s just at the top left corner all I can see it a leg . This is the code :

local options = { -- Required parameters width = 50, height = 41, numFrames = 2, -- Optional parameters; used for scaled content support sheetContentWidth = 70, -- width of original 1x size of entire sheet sheetContentHeight = 82 -- height of original 1x size of entire sheet } local imageSheet = graphics.newImageSheet( "images3.png", options ) -- sequences table local character = { -- consecutive frames sequence { name = "normalRun", start = 1, count = 8, time = 800, loopCount = 0, loopDirection = "forward" } } -- consecutive frames local sequenceData = { name="walking", start=3, count=6, time=100, loopCount = 0, -- Optional ; default is 0 (loop indefinitely) loopDirection = "bounce" -- Optional ; values include "forward" or "bounce" } local character = display.newSprite( imageSheet, sequenceData ) -- sprite listener function local function spriteListener( event ) local thisSprite = event.target -- "event.target" references the sprite if ( event.phase == "ended" ) then thisSprite:setSequence( "fastRun" ) -- switch to "fastRun" sequence thisSprite:play() -- play the new sequence end end 

 character:addEventListener( "sprite", spriteListener )

From what I can tell, you haven’t positioned the sprite where you want it, or given it any commands to move.

 

I see multiple problems here:

First, the optional parameters do not make sense, if the frames are the same size. I will provide you with an example.

Second, define where you want the character to spawn on screen. Set a character.x and character.y.

Also, you have no sequence called fastRun, only normalRun.

There are two character variables defined.

The animation is not great but this is just the basics of it.

Do not copy the entire code, just take the pieces you need, or use it as reference.

This kind of helps . When I run the code it shows but I only see the legs in a medium sized square on the screen I don’t know how to fix this . My guess is that maybe it’s running that way because your using composer and i’m using storyboard . I’ll try to fix the code until I get an answer . My code :

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local physics = require "physics" physics.start() -- background -------------------------------------------- local character -- forward declarations and other locals local options = { width = 100, height = 125, numFrames = 20, sheetContentWidth = 500, sheetContentHeight = 500 } local sheet = graphics.newImageSheet("images3.png", options) local sequence = { name = "walk", start = 11, count = 10, time = 750, loopCount = 0 --for infinite looping } local screenW, screenH, halfW = display.actualContentWidth, display.actualContentHeight, display.contentCenterX

function scene:createScene(event) local screenGroup = self.view local background = display.newImageRect("images.png",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) character = display.newSprite(sheet, sequence) character.x = 100 character.y = 300 character:scale(-1, 1) character:play() end

function scene:enterScene(event) Runtime:addEventListener("collision", onCollision) gun:addEventListener( "touch", shootBullet ) if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then -- Called when the scene is now on screen transition.to(character, {x = display.screenOriginX, time = 4000, onComplete = function(self) if (character.isPlaying == true) then character:pause() end end}) -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc. physics.start() end end

function scene:exitScene(event) Runtime:removeEventListener("collision", onCollision) if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) physics.stop() elseif phase == "did" then -- Called when the scene is now off screen end end function scene:destroyScene(event) -- Called prior to the removal of scene's "view" (sceneGroup) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. local sceneGroup = self.view package.loaded[physics] = nil physics = nil end

Just figured something out . It’s not that i’m using storyboard . I don’t know what the problem is but i’ll try to find out

It might be that your options table is not set up correctly. Can you upload images3.png somewhere so we know what we’re dealing with?

function scene:createScene(event) local screenGroup = self.view local background = display.newImageRect("images.png",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) centerX = 230 centerY = 60 round = 1 roundTxt = display.newText( "Round: "..round, centerX, centerY, native.systemFontBold, 20 ) gun = display.newImage("pistol.gif") gun.x = 50 gun.y = 300 screenGroup:insert(gun) cart = display.newImage("cart.png") cart.x = 100 cart.y = 70 screenGroup:insert(cart) character = display.newSprite(sheet, sequence) character.x = 100 character.y = 300 character:scale(-1, 1) character:play() end

The code below is above all of the scenes (not in any scenes) :

-------------------------------------------- local character -- forward declarations and other locals local options = { width = 100, height = 125, numFrames = 20, sheetContentWidth = 500, sheetContentHeight = 500 } local sheet = graphics.newImageSheet("zombiee.gif", options) local sequence = { name = "walk", start = 11, count = 10, time = 750, loopCount = 0 --for infinite looping } local screenW, screenH, halfW = display.actualContentWidth, display.actualContentHeight, display.contentCenterX

IF you are using your own image do not use my options table nor my sequence table. Also, quick question, is the GIF working for you? I just want to know if Corona supports this. I do not want to draw attention away from your question.

Also, please upload your image so we can help you with the options table.

Ok, the problem I see here is that the individual frames have to be spread out in an imageSheet, (don’t quote my on this) but, I think that’s the only way. Try splitting up the GIF into frames into an image sheet.

Corona does not support animated GIFs. @sdktester15 is correct. Each GIF frame would need to be it’s own image in a sprite sheet.

Rob