I’ve read lots of posts and looked at lot’s of generic code but as usual, I think I could understand it better if I had some code specific to my situation.
I have objects that spawn. These spawned objects are the same size/shape and all have the same physics. The only differences between them are the colors.
ex. square-red.png, square-orange.png, square-blue.png
etc…about 8- 10 different colors.
what i would like to happen is that if I click on a certain object (square-red.png) and then click on a different object (square-blue.png) then the two objects switch places. This would have to be available with any of the spawned objects…does that make sense?
here’s a snippit of my code:
local diamondGfx = { “square-yellow.png”, “square-orange.png”, “square-blue.png”, “square-red.png”,
“square-aqua.png”, “square-green.png”, “square-purple.png”, “square-white.png” }
------------------------------------------------ table for storing objects created in TABLE diamondGfx
local alldiamonds = {}
------------------------------------------------------------new spawn diamond
local function spawndiamond( )
– audio.play( popSound )
randImage = diamondGfx[math.random( 1, 8 )]
alldiamonds[#alldiamonds + 1] = display.newImage( randImage )
local diamond = alldiamonds[#alldiamonds]
diamond.x = 50 – could be randomised?
diamond.y = 100 – could be randomised?
physics.addBody( diamond, { density=0.0, friction=0.0, bounce=0.2 } )—add radius=00.8 specify collision spot. middle (not outer edge) of object is collision
---------------listen at diamond(s) for a touch. If there is then go to event “local function dragBody (event)”
diamond:addEventListener( “touch”, dragBody )
-------------------------------------------------------------------------needs to be within “local function spawndiamond” to work
local diamondmove = diamond----------------------------------------------CODE TO MOVE DIAMONDS FROM ONE POINT TO ANOTHER
physics.addBody( diamondmove, { density=1.5, friction=0.6, radius=00.3, bounce=0.3 } )
diamondmove.x=40
diamondmove.y=60 [import]uid: 127842 topic_id: 22570 reply_id: 322570[/import]
[import]uid: 52491 topic_id: 22570 reply_id: 90122[/import]