I was trying to come up with a way to simulate an the sand in an hour glass. The solution I came up with created hundreds of 2px circles each with their own body, and letting gravity do its job. Needless to say, this wasn’t very elegant and the execution ran very slow, I’m guessing due to an overuse (misuse) of system resources. Any thoughts on how I could better code this? Thanks! [import]uid: 23185 topic_id: 14438 reply_id: 314438[/import]
I did this using my own hourglass and Particle Candy. If you’re interested in the code let me know and I’ll post it. [import]uid: 40033 topic_id: 14438 reply_id: 53450[/import]
I’d suggest you use a SpriteSheet instead, but here’s how you can do it by hacking the ShapeTumbler example, heh:
http://jessewarden.com/archives/corona/hourglass.zip [import]uid: 23693 topic_id: 14438 reply_id: 53453[/import]
@jesterxl: Thanks! I tried using the ShapeTumbler example to start, but in order to get it to look more realistic, the size of ‘balls’ needed to be small, resulting in >1000 balls. So it slowed everything down. I’m not clear on how a SpriteSheet would help on this… could you elaborate some more?
[import]uid: 23185 topic_id: 14438 reply_id: 53454[/import]
@fava: Yes please. This will also let me know if PC is worth getting. [import]uid: 23185 topic_id: 14438 reply_id: 53455[/import]
Until we get particle systems like Papaya has, or bitmap methods like Flash has, you cannot scale particle systems in the way you want. Like you said, once you get tons of objects, it’ll slow down.
If you use something like After Effects with it’s Particle Playground, you’ll be able to create something like you want.
Then, export out a series of frames from it.
Then, import those frames into a Corona movieclip.
I’m not sure how Particle Candy works, but it appears to take arbitrary DisplayObjects and apply physics + alpha. If you start with transparent PNG’s, you can get some good looking effects like shown in the video. Notice, though, the video doesn’t really show more than 60 particles. I have a feeling you’ll not get the effect you want, but either way, post if it does, curious to see. [import]uid: 23693 topic_id: 14438 reply_id: 53458[/import]
Here’s the code, that’s all of it for the animation and the clean up functions. Memory was an issue but I just made a small image consisting of 4 particles and used 25 as the emission rate and the effect still came out good (IMO). Here’s a link so you can see it in action: http://youtu.be/3vGgq3oOpio
[lua]local Particles = require(“lib_particle_candy”)
– HOURGLASS FUNCTION
function doHour()
hourglass = display.newImage(“images/hourglass.png”, 130, 169)
hourglass:setReferencePoint(display.CenterReferencePoint)
hourglass.x = sceneCenterx; hourglass.y = 160; hourglass.alpha = 0.90
hourglass.xScale = 0.85; hourglass.yScale = 0.95
– CREATE EMITTERS (NAME, SCREENW, SCREENH, ROTATION, ISVISIBLE, LOOP)
Particles.CreateEmitter(“sandEmitter”, hourglass.x, hourglass.y-45, 0, false, false)
– DEFINE PARTICLE TYPE PROPERTIES
local Properties = {}
Properties.imagePath = “images/sand.png”
Properties.imageWidth = 28
Properties.imageHeight = 20
Properties.velocityStart = 10
Properties.velocityVariation = 20
Properties.directionVariation = 75
Properties.alphaStart = 0.20
Properties.alphaVariation = .40
Properties.fadeInSpeed = 2.0
Properties.fadeOutSpeed = -1.0
Properties.fadeOutDelay = 1000
Properties.scaleStart = 0.01
Properties.scaleVariation = 0.15
Properties.scaleInSpeed = 0.25
Properties.weight = 0.2
Properties.rotationVariation = 360
Properties.rotationChange = 0
Properties.emissionShape = 0
Properties.killOutsideScreen = true
Properties.lifeTime = 1100
Properties.useEmitterRotation = false
Particles.CreateParticleType (“Sand”, Properties)
– FEED EMITTERS (EMITTER NAME,PARTICLE TYPE NAME,EMISSION RATE, DURATION,DELAY)
Particles.AttachParticleType(“sandEmitter”, “Sand” , 25, 99999,0)
Particles.StartEmitter(“sandEmitter”)
theSandEmitter = Particles.GetEmitter(“sandEmitter”)
– SAND LOOP
function sandLoop( event )
Particles.Update()
end
Runtime:addEventListener(“enterFrame”, sandLoop)
sceneGroup:insert(theSandEmitter)
sceneGroup:insert(hourglass)
end
– END HOURGLASS FUNCTION
— CLEANUP FUNCTION
– REMOVE HOURGLASS
if hasHour then
if (theSandEmitter ~= nil) then
theSandEmitter = nil
Particles.CleanUp()
end
if hourglass then
hourglass:removeSelf()
hourglass = nil
end
Runtime:removeEventListener(“enterFrame”, sandLoop)
if bgImgHourTrans then transition.cancel(bgImgHourTrans) end
if (bgImgHour ~= nil) then
bgImgHour:removeSelf()
bgImgHour = nil
end
collectgarbage( “collect” )
end
– END CLEAN UP FUNTION[/lua] [import]uid: 40033 topic_id: 14438 reply_id: 53467[/import]