Showing posts with label ansca. Show all posts
Showing posts with label ansca. Show all posts

Wednesday, 24 July 2013

Auto-change the physics of an object (created using Physics Editor) after a change of it's size in corona SDK

If you are using physics editor for making physics objects in your corona game, then at some point you may doubted about how to scale the physics area according to the sprite scale values... But it is very simple.

For doing such alternation, there is scaleFactor provided. You can assign physics to the object with this scale factor, as below:

    local scaleFactor = 1.0
    local physicsData = (require "shapedefs").physicsData(scaleFactor)
    local shape = display.newImage("objectname.png")
    physics.addBody( shape, physicsData:get("objectname") )


And when you change the scaleFactor, the size of physics area will automatically change.

How to mail a screen captured image using corona SDK

For doing this, you have to:
  • First create a localgroup.
  • Then add the screen objects to that group.
  • Return the display group
  • Use display.save to save the entire group displayed.
  • Create mail option and add attachment image from baseDirectory
  • Call mail Popup
Example: 

-- creating the display group --
local localGroup = display.newGroup()  

-- creating display objects and adding it to the group --
local bg = display.newRect(0,0,320,480)
bg.x = 160
bg.y = 240
bg:setFillColor(150)
localGroup:insert(bg)

local rect = display.newRect(0,0,50,50)
rect.x = 30+math.random(260)
rect.y = 30+math.random(420)
localGroup:insert(rect)

-- Then do as follows --
local function takePhotoAndSendMail()
  -- take screen shot to baseDirectory --
  local baseDir = system.DocumentsDirectory
  display.save( localGroup, "myScreenshot.jpg", baseDir )

  -- Create mail options --
  local options =
  {
    to = { "devblogdk@gmail.com",},
    subject = "My Level",
    body = "Add this...",
    attachment =
    {
      { baseDir=system.DocumentsDirectory, filename="myScreenshot.jpg", 
        type="image" },
    },
  }

  -- Send mail --
  native.showPopup("mail", options)
end
rect:addEventListener("tap",takePhotoAndSendMail)