How to move a character left

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

The second one is a png and it still doesn’t work

The point is, all images for the same sequence need to be on a single-layer png. Imagine the letters below (A - L) are frames in an animation - you would lay out your spritesheet in the same way.

A B C

D E F

G H I

J K L

Then you need to define your options table based on how big each frame is and the gaps between each frame. The values will be unique to your file so can’t just be copied from here, otherwise you will just get fragments of a frame and a jumbled mess.

How do I create this ?

You could use GIF splitter online and then just put the images together on Photoshop. Or use a free trial of Texture Packer:

https://www.codeandweb.com/texturepacker

Highly recommend texture packer. What it does is take individual images and position them neatly as a single image, ready to use in Corona. It will even generate the lua code for you so you don’t have to calculate the options table.

I’d also recommend buying a few assets from graphic river to practice with. For as little as $9 you can have a complete character, including all the typical animations you’d need like walk, jump, punch, die, slide etc. Put those into texture packer and you’re away.

Couldn’t find any good tutorials that explain the process of creating the sprites . Any other good makers ?