====== Creating Particle Explosions ====== Do you like blowing things up? Of course you do. Everyone does. How about a nice way to have particle explosions in your game? Great for bullet stormers. This explosion is quite simple. It is composed of the following objects: - A blank object - A spawner attached to the blank object above - A separate particle object which serves as the type of object the spawner shoots out This blank object can be placed anywhere. We'll limit it to 10 spawned particle objects, then it will die. We are looking for this kind of effect (though a still image doesn't do it justice): {{tutorials:animation:explode-screenshot.png|}} For this tutorial, the mouse will be used to set an explosion. Click anywhere on screen, and you can click as much and as quickly as you like to fill the screen with booms. ===== Setting Up And Input ===== Start with a blank, working orx project. In your Init() method, add a handler for input so we can read the mouse to set explosions: orxEvent_AddHandler(orxEVENT_TYPE_INPUT, EventHandler); Our event handler method with look like this: orxSTATUS orxFASTCALL EventHandler(const orxEVENT *_pstEvent) { if (_pstEvent->eType == orxEVENT_TYPE_INPUT){ if(orxInput_IsActive("LeftMouse") && orxInput_HasNewStatus("LeftMouse") ) { orxVECTOR mouseLocalScreenPosition = { 0.0, 0.0, 0.0 }; orxMouse_GetPosition(&mouseLocalScreenPosition); ExplodeAt(mouseLocalScreenPosition); } } return orxSTATUS_SUCCESS; } In this event handler method, we are detecting if the left mouse has been clicked. The "LeftMouse" being called will be defined in our config: [Input] SetList = TutorialInput [TutorialInput] MOUSE_LEFT = LeftMouse KEY_ESCAPE = Quit ===== ExplodeAt() And Graphic ===== An ExplodeAt() function being called. This is where we create a an explosion and position it. We'll send it our current mouse position. The ExplodeAt() function looks like this: void ExplodeAt(orxVECTOR position){ orxOBJECT *explosion = orxObject_CreateFromConfig("Exploder"); orxObject_SetPosition(explosion, &position); } Now, what are our explosion frames going to look like? Below are the animation frames of a single sub-explosion. This is a 594 x 46 pixel animation sprite set, each frame being 46 x 46 pixels: {{tutorials:animation:explosion.png|}} As mentioned at the beginning, the blank explosion object will have a spawner, and this spawner will spawn 10 copies of these individual sub-explosions. Each will follow quickly after the other and be randomly placed away from the centre blank object. This will help the explosion look a little more natural. And each will be different from the last. ===== Project Setup Config ===== Everything else happens in the config. First, some more screen set up stuff: [Mouse] ShowCursor = true [Display] ScreenWidth = 640 ScreenHeight = 480 Title = Explosions [Viewport] Camera = Camera BackgroundColor = (40, 40, 100) [Camera] FrustumWidth = @Display.ScreenWidth FrustumHeight = @Display.ScreenHeight FrustumFar = 2.0 Position = (320.0, 240.0, -1.0) ===== Explosion Animation ===== Next, the sub explosion object, graphics and animation frames: [ExplodeObject] ;explosion object, the actual orange flare Graphic = ExplodeGraphic ;supplies default image size for all frames AnimationSet = ExplosionSet Position = (-20,-20,0) ~ (20,20,0) ;<--- random positions offset from the centre of the explosion core LifeTime = 0.35 ;