Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

making the objects movable is not working! why?
Started by Mcreator83 Nov 04 2010 11:05 AM

3 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Mcreator83

[GLOBAL: userInfoPane.html]
Mcreator83
  • Observer

  • 6 posts
  • Guests

hey guys so I had a look at the API reference page and fallowed the instructions there but i am not able to make the crates move so what am i doing wrong?

here is the script:

local physics = require "physics"
physics.start ()
system.activate( "multitouch" )

physics.setGravity()
gx, gy = physics.setGravity( 0, 9 )

local function dragBody ( event )
local body = event.target
local phase = event.phase
local stage = display.getCurrentStage ()

if "began" == phase then
stage:setFocus ( body, event.id )
body.isFocus = true

body.tempJoint = physics.newJoint ( "touch", body, event.x, evebt.y )

elseif body.isFocus then
if "moved" == phase then

body.tempJoint:setTarget ( event.x, event.y )

elseif "ended" == phase or "cabcelled" == phase then
stage:setFocus ( body, nil )
body.isFocus = false

body.tempJoint:removeSelf ()

end
end

return true
end
local ground = display.newImage( "ground.png" )
ground.x = display.contentWidth / 2
ground.y = 445
ground.myName = "ground"

physics.addBody( ground, "static", { friction=0.5, bounce=0.3 } )

local function spawnCrate()
local crate1 = display.newImage( "Bcu.png" )
crate1.x = math.random( 320 )
crate1.y = -50

local crate2 = display.newImage( "Bcu.png" )
crate2.x = math.random( 320 )
crate2.y = -30

local crate3 = display.newImage( "Jcu.png" )
crate3.x = math.random( 320 )
crate3.y = -60

local crate4 = display.newImage( "Rcu.png" )
crate4.x = math.random( 320 )
crate4.y = -60

local crate5 = display.newImage( "Pcu.png" )
crate5.x = math.random( 320 )
crate5.y = -60

physics.addBody( crate1, { density=3.0, friction=0.5, bounce=0.3 } )
physics.addBody( crate2, { density=3.0, friction=0.5, bounce=0.3 } )
physics.addBody( crate3, { density=3.0, friction=0.5, bounce=0.3 } )
physics.addBody( crate4, { density=3.0, friction=0.5, bounce=0.3 } )
physics.addBody( crate5, { density=3.0, friction=0.5, bounce=0.3 } )
end

timer.performWithDelay( 500, spawnCrate, 30 )

crate:addEventListener ( "touch", dragBody )
uid: 10351 topic_id: 3406 reply_id: 303406


[TOPIC: post.html]
#2

DVD Guy

[GLOBAL: userInfoPane.html]
DVD Guy
  • Observer

  • 20 posts
  • Corona SDK


"event" and "cancelled" are misspelled. The script runs fine when these are corrected.
uid: 5742 topic_id: 3406 reply_id: 10226


[TOPIC: post.html]
#3

JayantV

[GLOBAL: userInfoPane.html]
JayantV
  • Corona Geek

  • 1,740 posts
  • Corona SDK

If you run your scripts with the Corona Terminal, you can see a wealth of information, it will tell you the line number and also what the error it is facing.

I guess there should be a small document on the undocumented debugging functionality of Corona. Every developer should use this to see where and what they are doing wrong as there is no IDE as yet that checks for syntax.

cheers,

Jayant C Varma
uid: 3826 topic_id: 3406 reply_id: 10231


[TOPIC: post.html]
#4

Mcreator83

[GLOBAL: userInfoPane.html]
Mcreator83
  • Observer

  • 6 posts
  • Guests

hey thanks for answering. lol at that error.

So i corrected it and tried it again but still i can't move any of the crates...
uid: 10351 topic_id: 3406 reply_id: 10280



[topic_controls]
[/topic_controls]