I delved into particle editor for the first time last night with a view to adding some particle effects to a 2D game I've been making.
Hopefully the following advice will help others understand hot to get to grips with compiling their own incarnations of particle effects.
Thank you, and all due credit to AmarJSB for posting the code snippet example within the thread below:
https://forum.thegamecreators.com/thread/225812
I edited it slightly to accomodate myself trying to get to grips with the Particle editor, please find minor amendments to it below:
// Project: ParticleCodeSnipperv1
// Created: 20-12-30
// show all errors
//SetErrorMode(2)
// set window properties
SetWindowTitle( "ParticleCodeSnipperv1" )
SetWindowSize( 800,600,0)
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
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 )
//do
// Print( ScreenFPS() )
// Sync()
//loop
settings.fullScr = 1
settings.mainSize = 1.0
settings.scrollSpeed = 300.0
// Initialie AGK rendering
init()
// include the particle addon
#include "inc_gpup.agc"
// Initialize the particle system
gpup_init()
//partBack = gpup_loadEffect("magic_green", 0, 0, 0, 2.0)
partBack = gpup_loadEffect("birds", 0, 0, 0, 2.0)
gpup_emitterActive( partBack, gpup_active )
//partFront = gpup_loadEffect("magic_red", 500.0+0.7, 1.6, 0, 2.0)
partFront = gpup_loadEffect("birds", 500.0+0.7, 1.6, 0, 2.0)
gpup_emitterActive( partFront, gpup_active )
spriteLayer = LoadSprite("test.png")
SetSpritePosition(spriteLayer, 600, 600)
spriteBack = LoadSprite("back.jpg")
SetSpriteDepth(spriteBack, 110)
SetSpritePosition(spriteBack, 200, 200)
sBy#=200
// Main loop
do
settings.tmr = GetFrameTime()
// Update the particle system. Call this every refresh.
gpup_update()
checkSize()
settings.scrollX = settings.scrollX + GetJoystickX() * settings.tmr * settings.scrollSpeed
SetViewOffset(settings.scrollX, 0)
gpup_setGlobalPosition(partBack, Get3DVectorXFromScreen(260-settings.scrollX, 230), Get3DVectorYFromScreen(260, 230), 0)
gpup_setGlobalPosition(partFront, Get3DVectorXFromScreen(510-settings.scrollX, 209)+500, Get3DVectorYFromScreen(510, 209), 0)
Render2DBack()
ClearDepthBuffer()
Render3D()
Print(str(ScreenFPS()) )
Print("Active effects: "+str(gpup_settings.activeEffects))
SetSpritePosition(spriteLayer, 600, sBy#)
SetSpritePosition(spriteBack, 200, 200)
ClearDepthBuffer()
Render2DFront()
SetCameraPosition(1, GetCameraX(1)+500, 0, -10)
ClearDepthBuffer()
Render3D()
SetCameraPosition(1, GetCameraX(1)-500, 0, -10)
sBy#=sBy#-1
if sBy#<10
sBy#=500
endif
Swap()
//Sync()
if ( GetRawKeyState(27) ) then exit
loop
end
function checkSize()
x = GetDeviceWidth()
y = GetDeviceHeight()
if x<>settings.sx or y<>settings.sy
settings.sx = x
settings.sy = y
settings.scaler = 1920.0/settings.sx
SetVirtualResolution(settings.sx, settings.sy)
SetCameraOrthoWidth( 1, 10.0/settings.scaler )
endif
endfunction
function init()
settings.sx = GetMaxDeviceWidth()*settings.mainSize
settings.sy = GetMaxDeviceHeight()*settings.mainSize
settings.scaler = 1920.0/settings.sx
SetErrorMode(2)
SetWindowTitle( "Runtime Demo" )
SetAntialiasMode( 1 )
SetWindowSize( settings.sx, settings.sy, settings.fullScr)
SetWindowAllowResize(1)
SetVirtualResolution(settings.sx, settings.sy)
UseNewDefaultFonts( 1 )
SetPrintSize( 20 )
SetGenerateMipmaps( 1 )
SetSyncRate( 0, 0 )
setcamerarange(1, 0.1, 20)
SetClearColor( 20,30,130 )
SetCameraFOV(1, 0)
SetCameraOrthoWidth( 1, 10.0/settings.scaler )
SetCameraPosition( 1, 0, 0, -10.0 )
SetCameraLookAt(1, 0, 0, 0, 0)
SetGlobal3DDepth( 100 )
endfunction
type t_settings
sx as float
sy as float
mainSize as float
fullScr as integer
scrollSpeed as float
scaler as float
tmr as float
scrollX as float
endtype
global settings as t_settings
I'm pleased to say that I achieved pleasing results by doing the following associated with the minor amendments to the file:
1. Created a new project, pasted the following code into the projects main.agc
2. Created a test.png file - saved it in the projects 'media' folder.
3. Created a back.jpg file - saved it in the projects 'media' folder.
4. Opened the particle editor - saved the 'birds' folder so it could be used in AppGameKit Studio.
5. Copy the media file structure from the particle editor to the new project.
6. Navigated to the export folder - copied the 5 birds files into the new project media/effects folder.
7. Compiled and ran the project to see two layers of 'birds' flocking across the window.
Hope this example helps someone.