Hey again, unfortunately after testing it I can’t get it to work as it should. The placeholder is not draggable and the function set up just seems to pause the physics rather than doing what was intended.
Here’s a full copy of the code if you don’t mind taking a look over:
[code]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
require “sprite”
require “toggle”
local ui = require(“ui”)
local gameUI = require(“gameUI”)
local physics = require(“physics”)
physics.start()
physics.setGravity(0, 9.8)
physics.pause()
local dragBody = gameUI.dragBody – for use in touch event listener below
system.activate(“multitouch”)
display.setStatusBar(display.HiddenStatusBar)
physics.setDrawMode(“hybrid”) – overlays collision outlines on normal Corona objects
– Functions –
local function placeholder( event ) --creates the function for displaying placeholders
if physics.pause() == true then
transparentball.isVisible = false – hide objects
placeholderball.isVisible = true – insert variable?
end
end
local function play( event )
if physics.pause == false then
transparentball.x = placeholderball.x
transparentball.y = placeholderball.y
transparentball.isVisible = true
placeholderball.isVisible = false
end
end
function physicspause (event)
physics.pause()
end
function physicsstart (event)
physics.start()
end
function localDrag( event )
gameUI.dragBody( event, {maxForce=20000, frequency=10, dampingRatio=0.2, center=true} )
end
– PLACEHOLDERS –
local placeholderball = display.newImage(“graphics/transparentball.png”)
placeholderball.x = 160
placeholderball.y = 200
placeholderball:addEventListener( “touch”, dragBody )
–DRAW IMAGES
local background1 = display.newImage( “graphics/background.png” )
background1.x = 160
background1.y = 240
background1.xScale = 2.0
background1.yScale = 2.0
local btn1 = display.newImage(“graphics/button.png”)
btn1.x = 150
btn1.y = 10
btn1.xScale = 0.300
btn1.yScale = 0.300
btn1:addEventListener(“touch”, placeholder)
local btn2 = display.newImage(“graphics/button.png”)
btn2.x = 300
btn2.y = 10
btn2.xScale = 0.300
btn2.yScale = 0.300
btn2:addEventListener(“touch”, physicsstart)
local instruction = display.newText( “drag any object”, 80, 60, native.systemFontBold, 20 )
instruction:setTextColor( 255, 255, 255, 500 )
local ground = display.newImage(“graphics/floor.png”) – physical ground object
ground.x = 165
ground.y = display.contentHeight - ground.contentHeight/2
physics.addBody( ground, “static”, { friction=0.5, bounce=0.3 } )
local transparentball = display.newImage(“graphics/transparentball.png”)
transparentball.x = placeholderball.x
transparentball.y = placeholderball.y
transparentball.xScale = 1
transparentball.yScale = 1
physics.addBody(transparentball, {density=0.9, friction=0.3, bounce=0.2})
transparentball:addEventListener( “touch”, dragBody )
local yellow = display.newImage(“graphics/yellowball.png”)
yellow.x = 300
yellow.y = 200
physics.addBody(yellow, {density=0.9, friction=0.3, bounce=0.3})
local orange = display.newImage(“graphics/orangeball.png”)
orange.x = 400
orange.y = 200
orange.xScale = 0.1
orange.yScale = 0.1
physics.addBody(orange, {density=0.9, friction=0.3, bounce=0.3})
if transparentball.currentFrame == 3 then
– do something (win condition)
end
transparentball.myName = “transparentball”
red.myName = “red”
localGroup:insert(background1)
localGroup:insert(instruction)
localGroup:insert(ground)
localGroup:insert(transparentball)
localGroup:insert(placeholderball)
localGroup:insert(orange)
localGroup:insert(yellow)
localGroup:insert(btn1)
localGroup:insert(btn2)
return localGroup
end[/code] [import]uid: 90223 topic_id: 16105 reply_id: 59902[/import]