I was trying to make a simple toy for a 1½ year old kid, but got stuck on how to make the best pixel particles.
Since pixels are way small, I need a LOT of particles! But it looks like SetParticlesFrequency () only accept a max of 500 particles per second. Of course I can always create several sets of particles, but I don't like trying to hack it to support way more particles than it seem to be designed for.
I guess a 1x1 pixel sprite will take less effort to draw than a 16x16 pixel one. But I don't know where the bottleneck is. Perhaps it would be more effecient to create a larger sprite, like 16x16 pixels with 7 pixels in it, instead of seven 1x1 pixel sprites?
And when I run the app, it sometimes just goes black at startup. No idea what that is about!
// Project: touchTheScreen
// Created: 2018-01-03
// show all errors
SetErrorMode(2)
Global DeviceHeight as float
Global DeviceWidth as float
DeviceHeight = GetDeviceHeight()
DeviceWidth = GetDeviceWidth()
// set window properties
SetWindowTitle( "touchTheScreen" )
SetWindowSize( DeviceWidth, DeviceHeight, 1 )
SetWindowAllowResize( 0 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( DeviceWidth, DeviceHeight )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetGenerateMipmaps(0) // create mipmaps
SetDefaultMagFilter(0) // 0=nearest, 1=linear
SetDefaultMinFilter(0)
/////////////////////////////////////////////////////////////
// PARTICLES
/////////////////////////////////////////////////////////////
particleSize as float
particleSize = 1 // 1 = one pixel
global particleTargetImg as integer
particleTargetImg = LoadImage("particle-d.png")
// create a block of particles and set properties
funParticles = CreateParticles ( 3, 3 )
SetParticlesImage ( funParticles, particleTargetImg )
SetParticlesPosition (funParticles, 3, 3)
SetParticlesStartZone ( funParticles, 3, 3, 3, 3 )
SetParticlesDirection ( funParticles, 280.00, 0.00 )
SetParticlesLife ( funParticles, 3.0 )
SetParticlesSize ( funParticles, particleSize )
SetParticlesAngle ( funParticles, 360 )
SetParticlesFrequency ( funParticles, 520.0 )
SetParticlesVelocityRange ( funParticles, 0.01, 0.2 )
SetParticlesRotationRange( funParticles, 0, 0 )
SetParticlesMax( funParticles, -1 )
SetParticlesTransparency( funParticles, 1 ) // 0=off, 1=alpha transparency, 2=additive blending
SetParticlesColorInterpolation( funParticles, 1 ) // 1=smooth
AddParticlesColorKeyFrame ( funParticles, 0.0, 255, 255, 255, 255 ) // white
AddParticlesColorKeyFrame ( funParticles, 0.5, 255, 255, 0, 255 ) // yellow
AddParticlesColorKeyFrame ( funParticles, 1.0, 255, 115, 0, 255 ) // orange
AddParticlesColorKeyFrame ( funParticles, 1.5, 255, 0, 0, 191 ) // red
AddParticlesColorKeyFrame ( funParticles, 2.0, 192, 0, 130, 128 ) // magenta
AddParticlesColorKeyFrame ( funParticles, 2.5, 95, 0, 165, 64 ) // purpur
AddParticlesColorKeyFrame ( funParticles, 3.0, 0, 18, 165, 0 ) // blue
pOffset = 7 // How broad a starting area the particles are generated within
renderImg = CreateRenderImage (DeviceWidth, DeviceHeight, 0, 0)
do
print(GetParticlesFrequency( funParticles ) )
if GetRawKeyPressed(27) then End // end the program when you press escape
if GetRawKeyPressed(87) // pressing W to take screenshot
SetRenderToImage (renderImg, 0)
Render()
SaveImage( renderImg, "screenshot.jpg" )
ClearScreen()
setrendertoscreen ()
endif
if GetPointerState() = 1 // if the finger presses down on the screen
SetParticlesStartZone ( funParticles, GetPointerX() -pOffset, GetPointerY() -pOffset, GetPointerX() +pOffset, GetPointerY() +pOffset )
else
SetParticlesStartZone ( funParticles, -300, -300, -300, -300 )
endif
Sync()
loop