Hey fellow devs, just a quick question from a beginner so please forgive me.
Ok so have this very simple demo of game i have been working on, its going very well so far.
Basic game concept is you move your spaceship left to right and shoot the enemies (UFO.png)
My question is regarding shooting a bullet from the “center” of the spaceship (player) when the “shoot button”
is pressed and then move up the screen along the x axis the hit and destroy the enemy (UFO)
I just cant figure out how to ‘spawn’ the bullet when the button is pressed and then move up the x axis,
I imagine its something to do with time per frame or something along those lines.
If anyone can help me with this issue by maybe giving me a snippet of example code to put in or maybe a tutorial etc I would be very much grateful.
Kind Regards,
Jordan
Here is the code I have so far…
[code]
local physics = require(“physics”)
physics.start()
–> Hide the status bar
display.setStatusBar( display.HiddenStatusBar )
–> Display background image
local background = display.newImage( “background.png” )
–> Display button_a image and position
local button_a = display.newImage( “button_a.png” )
button_a.x = 100; button_a.y = 850
–> Display button_b image and position
local button_b = display.newImage( “button_b.png” )
button_b.x = 540; button_b.y = 850
–> Display bullet image and position
local bullet = display.newImage( “bullet.png” )
bullet.x = display.contentWidth / 2
bullet.y = 500
–> Display spaceship image and position
local spaceship = display.newImage( “spaceship.png” )
spaceship.x = 330; spaceship.y = 700
physics.addBody( spaceship, “static”, { density=1.0 } )
–> Add a new function using :touch (event) to move the
– spaceship .x position -20 when the “button_a” is pressed
function button_a:touch (event)
spaceship.x = (spaceship.x)-15
end
–> Add event listener (touch) to the “button_a” to link to the
– ‘function’ we just made above
button_a:addEventListener( “touch”, button_a )
–> Add a new function using :touch (event) to the move the
– spaceship .x position + 10 when the “button_b” is pressed
function button_b:touch (event)
spaceship.x = (spaceship.x)+15
end
–> Add event listener (touch) to the “button_b” to link to the
– ‘function’ we just made above
button_b:addEventListener( “touch”, button_b )
–> Display UFO image and position
local UFO = display.newImage( “UFO.png” )
UFO.x = 315
–> Display shoot button image and position
local button_fire = display.newImage( “button_fire.png” )
button_fire.x = display.contentWidth / 2
button_fire.y = 850
[code] [import]uid: 13946 topic_id: 5358 reply_id: 305358[/import]
[import]uid: 13946 topic_id: 5358 reply_id: 17880[/import]