Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Problem with control
Started by danka3819 Aug 06 2018 12:18 AM

1 reply to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

danka3819

[GLOBAL: userInfoPane.html]
danka3819
  • Observer

  • 1 posts
  • Corona SDK

Hi! I just recently started development on the Corona sdk and I already have a question. I made a control like in docementation on a corona web site:

local function dragShip(event)

  local ship = event.target
  local phase = event.phase

  if ("began" == phase) then
    display.currentStage:setFocus(ship)
    ship.touchOffsetY = event.y - ship.y

  elseif ("moved" == phase) then
    ship.y = event.y - ship.touchOffsetY

  elseif ("ended" == phase or "cancelled" == phase) then
    display.currentStage:setFocus(nil)
  end

  return true

end

And then I made a button for shooting:

fire = widget.newButton{
    shape = 'circle',
    radius = 50,
    x = display.contentWidth - 40,
    y = display.contentHeight - display.contentHeight  / 5,

    onPress = function(event)

      local newLaser = display.newImageRect(mainGroup, "png/shipLaser.png", 35, 7)
      physics.addBody(newLaser, "dynamic", {isSensor = true})
      newLaser.isBullet = true
      newLaser.myName = "shipLaser"

      newLaser.x = ship.x
      newLaser.y = ship.y
      newLaser:toBack()
      display.currentStage:setFocus(fire)

      transition.to(newLaser, {x = display.contentWidth + 300, time = 500,
        onComplete = function() display.remove(newLaser) end
      })
    end
  }

And there's a promlem: the movement of the box and shooting can not occur at the same time, that is, while I'm moving the ship, I can't shoot. Hrlp me pleeaase!



[TOPIC: post.html]
#2

Appletreeman

[GLOBAL: userInfoPane.html]
Appletreeman
  • Contributor

  • 382 posts
  • Corona SDK

You'll need to activate 'multiTouch'.

Add the following line to your code (I normally add it near the top of main.lua)

system.activate( "multitouch" )

For more details see the docs - Multitouch




[topic_controls]
[/topic_controls]