Help me jump my sprite

Hii, the sprite code is -

[code]

– A sprite sheet with a green dude
local sheet2 = sprite.newSpriteSheet( “greenman.png”, 128, 128 )
– ( “greenman.png”, 128, 128[decreasing this goes y axis down] )…these parameters are for best running

local spriteSet2 = sprite.newSpriteSet(sheet2, 1, 15)
sprite.add( spriteSet2, “man”, 1, 15, 200, 0 ) – play 15 frames every 200 ms

local instance2 = sprite.newSprite( spriteSet2 )
– change done reflects change on x-axis of the hero
instance2.x = 3 * display.contentWidth / 4 - 180

instance2.y = baseline - 55

instance2:prepare(“man”)
instance2:play()

[code]

and the button code is -

[code]
myBtn= display.newImage(“button.png”)
myBtn.x = 40
myBtn.y = 210
local function btnPressed (event)
instance2:applyLinearImpulse(0, -0.4, man.x, man.y)
print (“BUTTON PRESSED!”)

end
myBtn:addEventListener(“touch”, btnPressed)

[code]
i want to make my sprite jump, please guide me where am i going wrong ??

[import]uid: 120308 topic_id: 20858 reply_id: 320858[/import]

You are referring to man.x and man.y but your sprite appears to be called instance2 - fix that and let me know results.

Peach :slight_smile: [import]uid: 52491 topic_id: 20858 reply_id: 82654[/import]

hiii, it worked a bit…thanks…now i wanna make it perfect

2 quick things-

  1. want it not to go beyond mobile screen, whats wall graphics wrong here

–Define wall graphics
local leftWall = display.newRect(0, 0, 1, display.contentHeight)
local rightWall = display.newRect(display.contentWidth, 0, 1, display.contentHeight)
local ceiling = display.newRect(0, 0, display.contentWidth, 1)

  1. how can i make some other image or sprite collide to it, lets say - aunt.png [import]uid: 120308 topic_id: 20858 reply_id: 82656[/import]

The wall graphics look OK - have you made them static physics bodies though? If not they wont work.

If you do make them static physics bodies though then no dynamic objects (like your ball) will be able to pass through them.

Peach :slight_smile: [import]uid: 52491 topic_id: 20858 reply_id: 82677[/import]

u forgot to reply on 2nd point -

  1. how can i make some other image or sprite collide to it, lets say - aunt.png

i mean from my greenman [import]uid: 120308 topic_id: 20858 reply_id: 82684[/import]

Hi i suggest you read up on a few tutorials.

Take a look here : http://www.learningcorona.com

:slight_smile: [import]uid: 84637 topic_id: 20858 reply_id: 82690[/import]

You make them physics bodies, then they will collide.

If you want collision detection then see this tutorial, the final part explains how to use it correctly; http://techority.com/2011/06/19/corona-for-newbies-part-4-physics/

It is the same for any physics body whether it is an image or a sprite.

Peach :slight_smile: [import]uid: 52491 topic_id: 20858 reply_id: 82738[/import]