How to move a character left

You should definitely use Texture Packer, they give you a free trial and explain how to use on their website:

https://www.codeandweb.com/texturepacker

The website is saying just drop the image and press publish but nothing is happening 

You have to split the GIF into different png images and then drop all the separate files into TexturePacker.

How do I split the image in different png images ?

Maybe this site can help:  http://gif2sprite.com/

I’ve never used it, but it sounds like it will do the trick.

Rob

That worked but how do I show the image in my game ?

spritesheet.lua:

-- -- created with TexturePacker (http://www.codeandweb.com/texturepacker) -- -- $TexturePacker:SmartUpdate:d1805432715519b8c34272654540b10c:ce413b6e41be378fafcac5fd6113a88a:c46243f411ca86fe596665ab352bd775$ -- local sheetInfo = require("mysheet") local myImageSheet = graphics.newImageSheet( "sprite-zombieed4d7c54ace483fe0fef59a87ed1c5a17.jpg", sheetInfo:getSheet() ) local sprite = display.newSprite( myImageSheet , {frames={sheetInfo:getFrameIndex("sprite")}} ) local SheetInfo = {} SheetInfo.sheet = { frames = { { -- sprite-zombieed4d7c54ace483fe0fef59a87ed1c5a17 x=1, y=1, width=1356, height=104, }, }, sheetContentWidth = 1358, sheetContentHeight = 106 } SheetInfo.frameIndex = { ["sprite-zombieed4d7c54ace483fe0fef59a87ed1c5a17"] = 1, } function SheetInfo:getSheet() return self.sheet; end function SheetInfo:getFrameIndex(name) return self.frameIndex[name]; end return SheetInfo

game.lua:

-- requires local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local physics = require "physics" physics.start() -- background 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) end local sheetOptions = { width = 512, height = 256, numFrames = 8 } local moving\_zombie = graphics.newImageSheet( "sprite-zombieed4d7c54ace483fe0fef59a87ed1c5a17.png", sheetOptions ) -- sequences table local sequences\_movingZombie = { { name = "normalRun", start = 1, count = 8, time = 800, loopCount = 4 }, { name = "fastRun", frames = { 1,3,5,7 }, time = 400, loopCount = 0 }, } local moving\_Zombie = display.newSprite( sheet\_movingZombie, sequences\_movingZombie ) -- 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 local bullet = {} local bCounter = 1 local function shootBullet(event) if event.phase == "ended" then bullet[bCounter] = display.newImage( "bullet4.png",gun.x, gun.y, 6, 6 ) bullet[bCounter].value = bCounter physics.addBody( bullet[bCounter], "dynamic" ) bullet[bCounter].gravityScale = 0 bullet[bCounter].myName = "bullet" bullet[bCounter]:setLinearVelocity( 2100, -20 ) bCounter = bCounter + 1 end end Coins = 0 centerX = 350 centerY = 60 CoinsTxt = display.newText( "Coins: "..Coins, centerX, centerY, native.systemFontBold, 20 ) local onCollision=function( event ) if event.phase =="began" then Coins = Coins + 5 CoinsTxt.text="Coins: "..Coins end end function scene:enterScene(event) Runtime:addEventListener("collision", onCollision) gun:addEventListener( "touch", shootBullet ) moving\_Zombie:addEventListener( "sprite", spriteListener ) end function scene:exitScene(event) Runtime:removeEventListener("collision", onCollision) end function scene:destroyScene(event) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene

i have an error on this line :

local moving\_Zombie = display.newSprite( sheet\_movingZombie, sequences\_movingZombie )

error :

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

please help

If your game uses physics, use setLinearVelocity to move the character at the chosen speed.

If not, use an enterFrame listener to move the character on the X axis by a chosen number of pixels every frame.

I am getting this error :

game:30: attempt to call method 'setLinearVelocity' (a nil value)

This is the code I just entered :

 character = display.newImage("images3.png") character.x = 410 character.y = 296 character:setLinearVelocity( 2100, -20 ) physics.addBody(character, "static", {density=.1, bounce=0.2, friction=.2, radius=12}) screenGroup:insert(character)

I am using transitionmoveto but how do I make them walk ?

The error is because you can’t setLinearVelocity before you add the body.

Do you mean how to you animate them to look like they are walking?

I wouldn’t use transitions for this sort of game to be honest, which I assume to be some sort of endless runner?

Yes .

Kind of

Hello ? I still need help . This is what I have :

 character= display.newImage("images3.png") character.x = 410 character.y = 296 transition.moveTo( character, { x=100, y=300, time=50000 } ) physics.addBody(character, "static", {density=.1, bounce=0.2, friction=.2, radius=12}) screenGroup:insert(character)

They go in the right direction  u but they don’t walk , they slide . I am using storyboard 

Well they’ll only walk if you have animation frames of them walking…do you have those?  In order to animate an image, you’ll need to create a sprite.

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

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

https://docs.coronalabs.com/guide/media/imageSheets/index.html

I’d recommend downloading the free platformer template on the marketplace, which covers creating and animating sprites. 

https://marketplace.coronalabs.com/asset/sticker-knight-platformer

You need to create spirite sheet in order to make your actor move.You can do it here http://www.piskelapp.com/

And then set linear velocity or use transition command.

How do I upload my image ? Do I have to create my own character ?

This is what I have and it’s still not working :

local sheetOptions = { } local sheet\_movingZombie = graphics.newImageSheet( "images3.png", sheetOptions ) -- sequences table local sequences\_movingZombie = { -- non-consecutive frames sequence { name = "fastRun", frames = { 1,3,5,7 }, time = 400, loopCount = 0, loopDirection = "forward" } }

Well, in order to have a walking animated character, you will later have define it, like this:

character = display.newSprite(sheet\_movingZombie, sequences\_movingZombie)

Also, it seems your sheetOptions are blank, you will have to define the following properties in them:

local sheetOptions { width: --of each individual frame height: --of each individual frame numFrames: --number of total frames in the image sheet sheetContentWidth: --of the entire image sheet sheetContentHeight: --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 }

Where it says:

character= display.newImage("images3.png")

Replace With: 

character = display.newSprite(sheet\_movingZombie, sequences\_movingZombie)

Learn more here: https://docs.coronalabs.com/guide/media/spriteAnimation/index.html