Getting Sprite to Jump Forward

Hi,

I have a sprite sheet of a frog jumping that I created using texture packer. And what I want to achieve is when I click on the image the frog jumps forward a certain distance and stops until it is click again. I’ve managed to load the sprite and get the frog sprite to play when clicked (touched) but I am having a little trouble with stopping the sprite and how-to get it to jump forward here is the code so far:

[code]
local sprite = require “sprite”
local sheetData = require “myFrogs” – name of file created using texture packer

local _w = display.contentWidth/2
local _h = display.contentHeight/2

local spriteData = sheetData.getSpriteSheetData()
local spriteSheet = sprite.newSpriteSheetFromData(“images/myFrogs.png”, spriteData)
local spriteSet = sprite.newSpriteSet(spriteSheet, 1, 7) – number of images in spritesheet
local frogSprite = sprite.newSprite(spriteSet)

frogSprite.x = _w
frogSprite.y = _h

–when I uncomment this code the frog animation doesn’t play
–local function frogStop (event)
– if (event.phase ==“ended”) then
– frogSprite:pause()
–end
–end
–Runtime:addEventListener(“touch”, frogStop )

– code for frog animation
local function frogJump(event)
if(event.phase == “ended”) then
– can I use frogSprite:setLinearVelocity(x,y) here to have the frog jump forward?
frogSprite:play()
end
end
frogSprite:addEventListener(“touch”, frogJump)

[code] [import]uid: 167310 topic_id: 32143 reply_id: 332143[/import]

You might want to take a look at this video:

Code Example: Character Jumping - Corona SDK
http://www.youtube.com/watch?v=k2MixuzTFC8

It’s based off of the original video I found here:
http://www.youtube.com/watch?v=oE_45hJVf-E

The example code for the video is here:
https://github.com/jonbeebe/Character-Jump

I haven’t compared your code with the example to see how they could be both smashed together, but hopefully it will be helpful to you. [import]uid: 107536 topic_id: 32143 reply_id: 128005[/import]

Thanks for the vids I’ve looked at them but they only deal with making a single sprite jump. I have a sprite sheet with multiple images that I am trying make jump. I have tried using applyForce, applyLinearImpulse and setLinearVelocity methods but I can’t get the sprite to jump. Do these methods only work on a single sprite and not on a sprite sheet? [import]uid: 167310 topic_id: 32143 reply_id: 128063[/import]

Thanks for the vids I’ve looked at them but they only deal with making a single sprite jump. I have a sprite sheet with multiple images that I am trying make jump. I have tried using applyForce, applyLinearImpulse and setLinearVelocity methods but I can’t get the sprite to jump. Do these methods only work on a single sprite and not on a sprite sheet? [import]uid: 167310 topic_id: 32143 reply_id: 128064[/import]

@lblake,

To use these functions: applyForce, applyLinearImpulse and setLinearVelocity, your image needs a body.

Here are some useful guides on this topic:
http://developer.coronalabs.com/content/game-edition-physics-bodies#physics.addBody
http://developer.coronalabs.com/content/game-edition-box2d-physics-engine
http://developer.coronalabs.com/content/game-edition-physics-joints

Cheers,
Ed [import]uid: 110228 topic_id: 32143 reply_id: 128080[/import]

OK thanks emaurina I’ve managed to get my sprite to move using setLinearVelocity but this method just moves one static sprite. What I am trying to figure out is how-to animate a sprite sheet of several sprites. On clicking (touching) the sprites animate a frog jumping forward every time the frog is clicked? [import]uid: 167310 topic_id: 32143 reply_id: 128085[/import]

@lblake,

Is this anything like what you’re trying to do? ==> http://www.youtube.com/watch?v=9b1dc2_P7KE

If no, how is what you want different. Also, could I see your sprite image and texturepacker file? If you mail the texture and the lua file to me at roaminggamer at gmail dot com, that would help a bit.

Thanks,

Ed M. [import]uid: 110228 topic_id: 32143 reply_id: 128120[/import]

You might want to take a look at this video:

Code Example: Character Jumping - Corona SDK
http://www.youtube.com/watch?v=k2MixuzTFC8

It’s based off of the original video I found here:
http://www.youtube.com/watch?v=oE_45hJVf-E

The example code for the video is here:
https://github.com/jonbeebe/Character-Jump

I haven’t compared your code with the example to see how they could be both smashed together, but hopefully it will be helpful to you. [import]uid: 107536 topic_id: 32143 reply_id: 128005[/import]

Thanks for the vids I’ve looked at them but they only deal with making a single sprite jump. I have a sprite sheet with multiple images that I am trying make jump. I have tried using applyForce, applyLinearImpulse and setLinearVelocity methods but I can’t get the sprite to jump. Do these methods only work on a single sprite and not on a sprite sheet? [import]uid: 167310 topic_id: 32143 reply_id: 128063[/import]

Thanks for the vids I’ve looked at them but they only deal with making a single sprite jump. I have a sprite sheet with multiple images that I am trying make jump. I have tried using applyForce, applyLinearImpulse and setLinearVelocity methods but I can’t get the sprite to jump. Do these methods only work on a single sprite and not on a sprite sheet? [import]uid: 167310 topic_id: 32143 reply_id: 128064[/import]

@lblake,

To use these functions: applyForce, applyLinearImpulse and setLinearVelocity, your image needs a body.

Here are some useful guides on this topic:
http://developer.coronalabs.com/content/game-edition-physics-bodies#physics.addBody
http://developer.coronalabs.com/content/game-edition-box2d-physics-engine
http://developer.coronalabs.com/content/game-edition-physics-joints

Cheers,
Ed [import]uid: 110228 topic_id: 32143 reply_id: 128080[/import]

OK thanks emaurina I’ve managed to get my sprite to move using setLinearVelocity but this method just moves one static sprite. What I am trying to figure out is how-to animate a sprite sheet of several sprites. On clicking (touching) the sprites animate a frog jumping forward every time the frog is clicked? [import]uid: 167310 topic_id: 32143 reply_id: 128085[/import]

@lblake,

Is this anything like what you’re trying to do? ==> http://www.youtube.com/watch?v=9b1dc2_P7KE

If no, how is what you want different. Also, could I see your sprite image and texturepacker file? If you mail the texture and the lua file to me at roaminggamer at gmail dot com, that would help a bit.

Thanks,

Ed M. [import]uid: 110228 topic_id: 32143 reply_id: 128120[/import]

Hi Ed,

Thanks for your help with my code, the code you sent works exactly as I wanted. I really didn’t expect you to write the code for me (I was looking for a bit of advice). Thanks once again for your help…

[import]uid: 167310 topic_id: 32143 reply_id: 128266[/import]

Hi emaurina,
How did you solve the problem? I have similar problem.

I want to do animation when I touch and drag the object. During the drag I want the sprite to animate.

I my result is similar only move one static sprite.

Can you share your solution with us?

KC
[import]uid: 94613 topic_id: 32143 reply_id: 128364[/import]

@mycorona (KC),

You can see the code I used in the video ( http://www.youtube.com/watch?v=9b1dc2_P7KE) here:
https://github.com/roaminggamer/SSKCorona/blob/master/sampler/ssk_sampler/forumhelp/121020_sprite_jump_forward.lua

Specifically, look at the function: createSprite( x, y, scale )

Also, you can get the whole sampler and SSK here: https://github.com/roaminggamer/SSKCorona

I am currently very heads down working on a re-org, bug fix and initial documentation pass. Expect all of SSK including the sampler to get better fast.

Oh, if you have and Android or a Fire/Kindle you can download the latest build of the sampler and try it on your device.

http://downloads.roaminggamer.com/fire/sska.apk - Android Binary

http://downloads.roaminggamer.com/fire/ssk.apk - Kindle Fire (gen 1) Binary

Please let me know if you need more help, or clarification regarding the code link.

Cheers,
Ed
[import]uid: 110228 topic_id: 32143 reply_id: 128372[/import]

Hi Ed,

Thanks for your help with my code, the code you sent works exactly as I wanted. I really didn’t expect you to write the code for me (I was looking for a bit of advice). Thanks once again for your help…

[import]uid: 167310 topic_id: 32143 reply_id: 128266[/import]

Hi emaurina,
How did you solve the problem? I have similar problem.

I want to do animation when I touch and drag the object. During the drag I want the sprite to animate.

I my result is similar only move one static sprite.

Can you share your solution with us?

KC
[import]uid: 94613 topic_id: 32143 reply_id: 128364[/import]

@mycorona (KC),

You can see the code I used in the video ( http://www.youtube.com/watch?v=9b1dc2_P7KE) here:
https://github.com/roaminggamer/SSKCorona/blob/master/sampler/ssk_sampler/forumhelp/121020_sprite_jump_forward.lua

Specifically, look at the function: createSprite( x, y, scale )

Also, you can get the whole sampler and SSK here: https://github.com/roaminggamer/SSKCorona

I am currently very heads down working on a re-org, bug fix and initial documentation pass. Expect all of SSK including the sampler to get better fast.

Oh, if you have and Android or a Fire/Kindle you can download the latest build of the sampler and try it on your device.

http://downloads.roaminggamer.com/fire/sska.apk - Android Binary

http://downloads.roaminggamer.com/fire/ssk.apk - Kindle Fire (gen 1) Binary

Please let me know if you need more help, or clarification regarding the code link.

Cheers,
Ed
[import]uid: 110228 topic_id: 32143 reply_id: 128372[/import]

Hi Ed,

I am trying to do the same thing however the link to the code you submitted isnt working anymore! Anychance you can explain to me how this is done? Sorry for the inconvenience!

Thanks,
Siddig [import]uid: 203940 topic_id: 32143 reply_id: 142997[/import]