Need Help, cannon game, rotating

Ok, so i’ve started making a game, i’m still relatively new to lua, and this is my code so far:

display.setStatusBar( display.HiddenStatusBar ) --Hide status bar…

local physics = require (“physics”) --Require the physics library…

physics.start(); --start the physics engine

physics.setGravity( 0, 0 ) --Set gravity to 0

local background = display.newImage (“Grassland.png”)

local cannon

local cannonball

local cannonball = display.newGroup()

local shot = {}

cannon = display.newImage( “cannon.png”, 200, 217, true )

cannonbarral = display.newImage( “cannonbarral.png”, 200, 220, true )

function charge()

    gCircle.rotation = gCircle.rotation - 3

    impulse = impulse - 0.2

    if(gCircle.rotation < -46) then

        gCircle.rotation = -46

        impulse = -3.2

    end

end

function shot:touch(e)

    if(e.phase == ‘ended’) then

    Runtime:removeEventListener(‘enterFrame’, charge)

        gCircle.isVisible = false

        gCircle.rotation = 0

end

local cannonball = display.newImage(‘cannonball.png’, 84, 220)

physics.addBody(cannonball, {density = 1, friction = 0, bounce = 0})

cannonball:insert(cannonball)

cannonball:applyLinearImpulse(dir, impulse, cannonball.x, cannonball.y ) end

now my problems are as follows:

i cant get cannonball.png to load

i need the cannon to shoot on touch

and i need the cannonbarral.png to rotate when i click to fire, and for cannonball.png to come out of the base point

I’m sorry, they are reallY newby problems

thanks

Sorry, not final images, i’m doing coding first problem # 1:

i cant get it to load, i put the file name in there, and it is correct:

local cannonball = display.newImage(‘cannonball.png’, 84, 220)

physics.addBody(cannonball, {density = 1, friction = 0, bounce = 0})

cannonball:insert(cannonball)

cannonball:applyLinearImpulse(dir, impulse, cannonball.x, cannonball.y ) end

 

Problem #2:

the cannon wont shoot when i do the: function shot:touch(e)

    if(e.phase == ‘ended’) then

    Runtime:removeEventListener(‘enterFrame’, charge)

        gCircle.isVisible = false

        gCircle.rotation = 0

end

 

and i need the cannonbarral.png to rotate when i click to fire, and for cannonball.png to come out of the base point:

 

7585a4f92280e0b3ab3928f107002793.png

cannonball:insert (cannonball) - why do you insert image to itself?

You use ‘impuls’ variable but what it is? You only use it but not create it

Hi @kkajr,

As @piotrz55 hints, the first and immediate issue is that you have two local variables named “cannonball”, one a group, and later, the other an image. Please be careful in naming your variables, and using the proper scope. You may find this video useful on the topic, located in Corona University (http://www.coronalabs.com/resources/tutorials/corona-basics/):

http://www.youtube.com/watch?v=2ATlcGP2zMY

Sorry, not final images, i’m doing coding first problem # 1:

i cant get it to load, i put the file name in there, and it is correct:

local cannonball = display.newImage(‘cannonball.png’, 84, 220)

physics.addBody(cannonball, {density = 1, friction = 0, bounce = 0})

cannonball:insert(cannonball)

cannonball:applyLinearImpulse(dir, impulse, cannonball.x, cannonball.y ) end

 

Problem #2:

the cannon wont shoot when i do the: function shot:touch(e)

    if(e.phase == ‘ended’) then

    Runtime:removeEventListener(‘enterFrame’, charge)

        gCircle.isVisible = false

        gCircle.rotation = 0

end

 

and i need the cannonbarral.png to rotate when i click to fire, and for cannonball.png to come out of the base point:

 

7585a4f92280e0b3ab3928f107002793.png

cannonball:insert (cannonball) - why do you insert image to itself?

You use ‘impuls’ variable but what it is? You only use it but not create it

Hi @kkajr,

As @piotrz55 hints, the first and immediate issue is that you have two local variables named “cannonball”, one a group, and later, the other an image. Please be careful in naming your variables, and using the proper scope. You may find this video useful on the topic, located in Corona University (http://www.coronalabs.com/resources/tutorials/corona-basics/):

http://www.youtube.com/watch?v=2ATlcGP2zMY