Thanks for the recommendation. I try it and the code says the file was remove but my image still cache the previous version. Any idea why?
Here are my changes: See line 75
Here are the changes to try it out.
http://db.tt/YK0z21pm
Thanks again for your help. ;- )
[code]
–
– level1.lua
local ui = require(“ui”)
local level1 = {}
local physics = require “physics”
–physics.setDrawMode( “hybrid” ) – uncomment to see physics bodies; “debug” shows only physics bodies
physics.start()
– local variables
local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth*0.5
local function cleanStage()
– Loop through all display objects currently on screen and remove them.
local stage = display.getCurrentStage()
for i=stage.numChildren,1,-1 do
display.remove( stage[i] )
end
end
– camera capture
local onCameraComplete = function (event)
local t = event.target
if t ~= nil then
– Scale and move the image to fit on display completely
t.xScale = display.contentWidth / t.width
t.yScale = t.yScale * t.height / t.width
t.x = t.height / 2
t.y = t.width / 2
local g = display.newGroup()
g:insert(t)
print (“g.width”, g.width )
display.save( g, “newPhoto1.jpg”, system.DocumentsDirectory)
g:removeSelf( )
end
end
local onCamTouch = function(event)
if event.phase == “release” then
media.show(media.Camera, onCameraComplete);
local baseDir = system.DocumentsDirectory
photo = display.newImageRect(“newPhoto1.jpg”, baseDir, 50, 50)
if photo ~= nil then
photo:scale(1, 1)
photo.x, photo.y = 400, -200
photo.rotation = 15
print (“photo.width:”, photo.width)
– add physics to the crate
physics.addBody( photo, { density=1.0, friction=0.3, bounce=0.3 } )
photo:toFront()
end
– Delete file that was cache previously
local results, reason = os.remove( system.pathForFile( “newPhoto1.jpg”, baseDir ) )
if results then
print( “file removed” )
else
print( “file does not exist”, reason )
end
end
end
–
– The level1.loadScreen() function (below) will be called first.
function level1.loadScreen()
cleanStage()
– create a grey rectangle as the backdrop
local background = display.newRect( 0, 0, screenW, screenH )
background:setFillColor( 128 )
– create a grass object and add physics (with custom shape)
local grass = display.newImageRect( “grass.png”, screenW, 82 )
grass:setReferencePoint( display.BottomLeftReferencePoint )
grass.x, grass.y = 0, display.contentHeight
– define a shape that’s slightly shorter than image bounds (set draw mode to “hybrid” or “debug” to see)
local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 }
physics.addBody( grass, “static”, { friction=0.3, shape=grassShape } )
– Adding camera button
local cameraBtn = ui.newButton{
defaultSrc = “camera.png”,
defaultX = 54,
defaultY = 54,
overSrc = “button.png”,
overX = 54,
overY = 54,
onEvent = onCamTouch,
id = “CameraButton”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
cameraBtn.x = 142;
cameraBtn.y = 288
cameraBtn.isVisible = true
cameraBtn.isActive = true
end
return level1
[code] [import]uid: 32566 topic_id: 17446 reply_id: 66766[/import]