hey
I am reading but how the heck can I use statics object even with isSensor=true to report collision events though not be moved when hit by other objects?
I have tried to make the stick a rectangle as you mentioned but still it did not help.
[lua]–> ninja stars
local gameUI = require(“gameUI”)
–> Add Physics
local physics = require( “physics” )
physics.start()
physics.setGravity(0, 0)
–> Hide the status bar
display.setStatusBar(display.HiddenStatusBar)
–> Adds a background image
local background = display.newImage( “images/background.png” )
–> bamboostick
local stick = display.newImage( “images/stick.png” )
stick.x = 50
stick.y = 150
physics.addBody( stick ,{})
stick.name = “stick”
–> score stuff
score = require (“score”)
local scoreInfo = score.getInfo()
score.init({
x = 0,
y = 0}
)
score.setScore(0)
–> function to drag
function dragBody( event )
– I have tweaked the gameUI dragBody event so it does not move in x position only y
gameUI.dragBody( event, { maxForce=20000, frequency=10, dampingRatio=0.2, center=true } ) – very tight dragging, snaps to object center
end
–> Function to randomly spawn crates
local randomCrate = function()
local crate
crate = display.newImage( “images/superninja.png” )
crate.x = 200 + math.random(230)
crate.y = 400
crate.name = “ninja”
local crateTrans = transition.to(crate, { time=math.random(500,1000), alpha=1 ,x=crate.x, y=(math.random(300)),onComplete=fireStar})
local function killMe(dudeToKill)
dudeToKill:removeSelf()
end
function fireStar(obj)
print(“FIRE!”)
local dude = display.newImageRect(“images/ninjastar1.png”,16,16)
physics.addBody( dude, { bounce=0} )
dude.x, dude.y = obj.x,obj.y
transition.to(dude, {time=math.random(500,2000), x=0, rotation=-360,onComplete=killMe})
local crateTrans = transition.to(obj, { time=math.random(500,1000), xScale=obj.xScale/2, yScale=obj.yScale/2, alpha=0 ,x=obj.x, y=500,onComplete=ninjeHide})
ninjaHide = function()
print( “Ninja gone!” )
end
end
function crate:tap( event )
print(event.target.name)
score.setScore (score.getScore()+event.target.score)
event.target:removeEventListener( “tap”, crate )
event.target:removeSelf()
end
crate:addEventListener( “tap”, crate )
end
local function onCollision(event )
if ( event.phase == “began” ) then
print(event.object1.name … " started")
elseif ( event.phase == “ended” ) then
print(event.object1.name … " ended" )
end
end
stick:addEventListener( “touch”, dragBody )
Runtime:addEventListener( “collision”, onCollision )
–> Make 100 ninjas jump up with 1000 milliseconds in between
timer.performWithDelay( 1000, randomCrate, 100 )[/lua] [import]uid: 22737 topic_id: 6160 reply_id: 21555[/import]