It's possible to develop game that reproduce sand/dust with fluid dynamics physics?
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
Sand/dust with fluid dynamics physics
Hi,
of course.. easy with corona..
i would say.. the sand are small balls..
if you want dust.. use particle candy ..
BR
There are examples of code for this?
I don't know Corona and If I buy Corona for iPhone it's included a support service?
here's an example to do something like this.
but honestly, the performance on an actual device is not very satisfying...
This works great with particle counts up to 100, but then it gets sloppy. I created this with much bigger objects (bouncing balls) and quickly changed it to "sand mode". There has to be a better solution, but you should get the idea:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | -- Project: PhysicsTest -- Description: particle physics test -- -- 2011 finefin local physics = require("physics") physics.start() physics.setGravity( 0, 40 ) --physics.setDrawMode( "hybrid" ) -- A general function for dragging physics bodies local function dragBody( event ) local t = event.target local phase = event.phase if "began" == phase then display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y if event.x > t.x then t.rotation = t.rotation - 10 elseif event.x < t.x then t.rotation = t.rotation + 10 end -- Make body type temporarily "kinematic" (to avoid gravitional forces) event.target.bodyType = "kinematic" -- Stop current motion, if any event.target:setLinearVelocity( 0, 0 ) event.target.angularVelocity = 0 elseif t.isFocus then if "moved" == phase then t.x = event.x - t.x0 t.y = event.y - t.y0 elseif "ended" == phase or "cancelled" == phase then display.getCurrentStage():setFocus( nil ) t.isFocus = false -- Switch body type back to "dynamic", unless we've marked this sprite as a platform if ( not event.target.isPlatform ) then event.target.bodyType = "dynamic" end end end -- Stop further propagation of touch event! return true end -- create world local wallLeft = display.newRect( 0, -50, 10, 530 ) physics.addBody( wallLeft, "static", { friction=0.5 } ) local wallRight = display.newRect( 310, -50, 10, 530 ) physics.addBody( wallRight, "static", { friction=0.5 } ) local platform1 = display.newRect( 0, 50, 200, 10 ) physics.addBody( platform1, "static", { friction=0.5 } ) platform1.rotation = 10 platform1:addEventListener( "touch", dragBody ) platform1.isPlatform = true local platform2 = display.newRect( 120, 150, 200, 10 ) physics.addBody( platform2, "static", { friction=0.5 } ) platform2.rotation = -10 platform2:addEventListener( "touch", dragBody ) platform2.isPlatform = true local platform3 = display.newRect( 0, 250, 200, 10 ) physics.addBody( platform3, "static", { friction=0.5 } ) platform3.rotation = 10 platform3:addEventListener( "touch", dragBody ) platform3.isPlatform = true -- create table for all particles local balls = {} -- remove particles that are out of bound local function ifOutOfBounds (event) for i,val in pairs(balls) do if(val.y > 480) or (val.y < -50) then val:removeSelf(); balls[i] = nil; end end end local randomBall = function() -- create ball local ball ball = display.newRect( 160, -20, 1, 1 ) ball.x = 160; ball.y = -20 physics.addBody( ball, { density=1, friction=0.6, bounce=0.1, radius=1 } ) ball.angularVelocity = math.random(800) - 400 -- add ball to table balls[#balls + 1] = ball end Runtime:addEventListener( "enterFrame", ifOutOfBounds ) timer.performWithDelay( 10, randomBall, -1 ) |
I don't think so actually. Fact of the matter is that doing something like that simulation is very CPU intensive and will not come out nicely via a scripting language. It's not as easy as AlenB thinks it is, box2d is not designed for that kind of simulation.
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
supported features matrix
Why not iWeb?
Potential memory leak using director 1.3 preview
Work In Progress Forum?
objects in a table
best way for displaying images on the bottom of the screen
Adding event listeners to sprites
Make images ignore transparent bits in png files?
Help with physic bodies [SOLVED]