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 :
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.
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 )
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
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.