I want to move my character walk/run left automatically without me touching the screen . I also want multiple characters to be running . They will be the same picture and screenGroup id but I want to make them move differently(E.g one is running one is walking . etc) . I looked on the Corona SDK forums but all the question I am seeing is how to move the character when they touch the character . Can someone help me ? I am using storyboard . I don’t like composer
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
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)