# Need Help, cannon game, rotating

**URL:** <https://forums.solar2d.com/t/need-help-cannon-game-rotating/318575>\
**Category:** Newbie Questions\
**Created:** [October 3, 2013, 10:59pm UTC](https://forums.solar2d.com/t/need-help-cannon-game-rotating/318575 "2013-10-03T22:59:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkajr](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/k/5f8ce5/32.png) [@kkajr](https://forums.solar2d.com/u/kkajr)\
**Post date:** [October 3, 2013, 10:59pm UTC](https://forums.solar2d.com/t/need-help-cannon-game-rotating/318575/1 "2013-10-03T22:59:56Z")

</div>

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()

&nbsp; &nbsp; gCircle.rotation = gCircle.rotation - 3

&nbsp; &nbsp; impulse = impulse - 0.2

&nbsp; &nbsp; if(gCircle.rotation \< -46) then

&nbsp; &nbsp; &nbsp; &nbsp; gCircle.rotation = -46

&nbsp; &nbsp; &nbsp; &nbsp; impulse = -3.2

&nbsp; &nbsp; end

end

function shot:touch(e)

&nbsp; &nbsp; if(e.phase == ‘ended’) then

&nbsp;&nbsp;&nbsp;&nbsp;Runtime:removeEventListener(‘enterFrame’, charge)

&nbsp; &nbsp; &nbsp; &nbsp; gCircle.isVisible = false

&nbsp; &nbsp; &nbsp; &nbsp; 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

---

<div class="post-metadata">

**Author:** ![kkajr](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/k/5f8ce5/32.png) [@kkajr](https://forums.solar2d.com/u/kkajr)\
**Post date:** [October 3, 2013, 11:07pm UTC](https://forums.solar2d.com/t/need-help-cannon-game-rotating/318575/2 "2013-10-03T23:07:37Z")

</div>

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

&nbsp;

Problem #2:

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

&nbsp; &nbsp; if(e.phase == ‘ended’) then

&nbsp;&nbsp;&nbsp;&nbsp;Runtime:removeEventListener(‘enterFrame’, charge)

&nbsp; &nbsp; &nbsp; &nbsp; gCircle.isVisible = false

&nbsp; &nbsp; &nbsp; &nbsp; gCircle.rotation = 0

end

&nbsp;

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

&nbsp;

![7585a4f92280e0b3ab3928f107002793.png](http://gyazo.com/7585a4f92280e0b3ab3928f107002793.png)

---

<div class="post-metadata">

**Author:** ![piotrz55](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@piotrz55](https://forums.solar2d.com/u/piotrz55)\
**Post date:** [October 4, 2013, 5:42am UTC](https://forums.solar2d.com/t/need-help-cannon-game-rotating/318575/3 "2013-10-04T05:42:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bjsorrentino](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bjsorrentino](https://forums.solar2d.com/u/bjsorrentino)\
**Post date:** [October 4, 2013, 8:03pm UTC](https://forums.solar2d.com/t/need-help-cannon-game-rotating/318575/4 "2013-10-04T20:03:53Z")

</div>

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.coronalabs.com/resources/tutorials/corona-basics/)):

[http://www.youtube.com/watch?v=2ATlcGP2zMY](http://www.youtube.com/watch?v=2ATlcGP2zMY)

---

<div class="post-metadata">

**Author:** ![kkajr](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/k/5f8ce5/32.png) [@kkajr](https://forums.solar2d.com/u/kkajr)\
**Post date:** [October 3, 2013, 11:07pm UTC](https://forums.solar2d.com/t/need-help-cannon-game-rotating/318575/5 "2013-10-03T23:07:37Z")

</div>

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

&nbsp;

Problem #2:

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

&nbsp; &nbsp; if(e.phase == ‘ended’) then

&nbsp;&nbsp;&nbsp;&nbsp;Runtime:removeEventListener(‘enterFrame’, charge)

&nbsp; &nbsp; &nbsp; &nbsp; gCircle.isVisible = false

&nbsp; &nbsp; &nbsp; &nbsp; gCircle.rotation = 0

end

&nbsp;

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

&nbsp;

![7585a4f92280e0b3ab3928f107002793.png](http://gyazo.com/7585a4f92280e0b3ab3928f107002793.png)

---

<div class="post-metadata">

**Author:** ![piotrz55](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@piotrz55](https://forums.solar2d.com/u/piotrz55)\
**Post date:** [October 4, 2013, 5:42am UTC](https://forums.solar2d.com/t/need-help-cannon-game-rotating/318575/6 "2013-10-04T05:42:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bjsorrentino](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bjsorrentino](https://forums.solar2d.com/u/bjsorrentino)\
**Post date:** [October 4, 2013, 8:03pm UTC](https://forums.solar2d.com/t/need-help-cannon-game-rotating/318575/7 "2013-10-04T20:03:53Z")

</div>

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.coronalabs.com/resources/tutorials/corona-basics/)):

[http://www.youtube.com/watch?v=2ATlcGP2zMY](http://www.youtube.com/watch?v=2ATlcGP2zMY)
