multi fire

I recently posted this in another conversation that was a little old, and I am posting it again here in the hopes that someone will see it.

I want to know if it is possible to send multiple objects from one point to another at the same time based on user input.

‘transition.to’ would work if you were launching one object at a time but say you wanted to have the player select multiple targets and have all of the objects fire at once?

Any ideas?

Thanks [import]uid: 102017 topic_id: 17396 reply_id: 317396[/import]

Let me see if I got this. You would have several targets. And you would tap on the targets, setting the aim. Then you would push a fire button launching all the bullets at the designated targets. If not, try to explain what you’re trying to accomplish. [import]uid: 66117 topic_id: 17396 reply_id: 65853[/import]

That is exactly what I am trying to accomplish. [import]uid: 102017 topic_id: 17396 reply_id: 65855[/import]

Here is a very simple example. Just copy and paste:
[lua]local _W = display.contentWidth
local _H = display.contentHeight

local target = display.newCircle(0,0,25)
target.x = _W/2; target.y = 77
target:setFillColor(255,0,0)

local ring1 = display.newCircle(0,0,20)
ring1.x = target.x; ring1.y= target.y;
ring1:setFillColor(255,255,255)

local ring2 = display.newCircle(0,0,15)
ring2.x = target.x; ring2.y= target.y;
ring2:setFillColor(255,0,0)

local ring3 = display.newCircle(0,0,10)
ring3.x = target.x; ring3.y= target.y;
ring3:setFillColor(255,255,255)

local marker = display.newCircle(0,0,10)
marker.x = _W-10; marker.y = _H-10;

local bullet = display.newRect(0,0,10,20)
bullet.x = _W/2; bullet.y = _H-50
bullet:setFillColor(255,255,0)

local fireButton = display.newCircle(0,0,15)
fireButton.x = 40; fireButton.y = _H-40
fireButton:setFillColor(0,255,0)

local function aim (e)
if e.phase == “moved” then
marker.x = e.x
marker.y = e.y
end
end
marker:addEventListener(“touch”, aim)

local function fire (e)
if e.phase == “ended” then
transition.to(bullet, {time = 400, x = marker.x, y = marker.y, xScale = .5, yScale = .5})
end
end
fireButton:addEventListener(“touch”, fire )[/lua]
In the game, the marker would be transparent [import]uid: 66117 topic_id: 17396 reply_id: 65862[/import]

Thank you for the assist. It’s just about where I had gotten too.

What I had envisioned would have multiple targets that could be tapped individually, then when fire was tapped the ‘bullets’ would all fly out at the same time to hit their assigned targets.

I’ll keep pluggin’ away. [import]uid: 102017 topic_id: 17396 reply_id: 65985[/import]

Here is multiFire version 1.3. LOL
[lua]local _W = display.contentWidth
local _H = display.contentHeight
local markerNumber = 1

local target = display.newCircle(0,0,25)
target.x = _W/2; target.y = 77;
target:setFillColor(255,0,0)

local target2 = display.newCircle(0,0,25)
target2.x = _W/2-100; target2.y = 77;
target2:setFillColor(255,0,0)
local target3 = display.newCircle(0,0,25)
target3.x = _W/2+100; target3.y = 77;
target3:setFillColor(255,0,0)

local marker1 = display.newCircle(0,0,10)
marker1.x = _W-10; marker1.y = _H-10; marker1:setFillColor(255,0,255)

local marker2 = display.newCircle(0,0,10)
marker2.x = _W-10; marker2.y = _H-10; marker2:setFillColor(0,255,0)

local marker3 = display.newCircle(0,0,10)
marker3.x = _W-10; marker3.y = _H-10; marker3:setFillColor(0,0,255)

local bullet1 = display.newRect(0,0,10,20)
bullet1.x = _W/2; bullet1.y = _H-50
bullet1:setFillColor(255,255,0)

local bullet2 = display.newRect(0,0,10,20)
bullet2.x = _W/2; bullet2.y = _H-50
bullet2:setFillColor(255,255,0)

local bullet3= display.newRect(0,0,10,20)
bullet3.x = _W/2; bullet3.y = _H-50
bullet3:setFillColor(255,255,0)

local fireButton = display.newCircle(0,0,15)
fireButton.x = 40; fireButton.y = _H-40
fireButton:setFillColor(0,255,0)

local function aim (event)
local t = event.target
if event.phase == “ended” then
if markerNumber == 1 then
marker1.x = event.x
marker1.y = event.y
elseif markerNumber == 2 then
marker2.x = event.x
marker2.y = event.y
elseif markerNumber == 3 then
marker3.x = event.x
marker3.y = event.y
end
markerNumber = markerNumber+1
end
end
Runtime:addEventListener(“touch”, aim)

local function fire (e)
if e.phase == “ended” then
transition.to(bullet1, {time = 400, x = marker1.x, y = marker1.y, xScale = .5, yScale = .5})
transition.to(bullet2, {time = 400, x = marker2.x, y = marker2.y, xScale = .5, yScale = .5})
transition.to(bullet3, {time = 400, x = marker3.x, y = marker3.y, xScale = .5, yScale = .5})
end
end
fireButton:addEventListener(“touch”, fire )[/lua]
I’m sure there is a more efficient way of doing this, but I thought I would go ahead and get this out here.

Good luck,
J.K. [import]uid: 66117 topic_id: 17396 reply_id: 65989[/import]

This is certainly more like what I was looking for.

I am very appreciative of your help, thanks.

[import]uid: 102017 topic_id: 17396 reply_id: 65992[/import]

Don’t mention it. { : -) Let me know if I can be of any more service.

Good luck,
J.K. [import]uid: 66117 topic_id: 17396 reply_id: 65997[/import]