2D Platformer template
A side-scroller on Kenney art: a tilemap level with platforms, coins to collect, slimes to stomp, a goal flag and a camera that follows the hero.
The 2D Platformer template is a side-scroller on Kenney Platformer Pack Redux art. Twelve coins sit on the ground and on six floating platforms. Three slimes patrol the ground: land on one from above to stomp it and bounce, but touch one from the side and the hero goes back to the start. A goal flag at the right end of the level shows the totals. The coin and stomp counters and the level-complete message are on the HUD, which reads the platformer.* HUD sources. The APlatformerPickupActor, APlatformerPatrolActor and APlatformerGoalActor classes come from the Platformer Kit and can be placed from the Gameplay category.
Originally the template was a pixel-art side-scroller. A 64 by 24 tile level has two ground runs with a pit and a water pool, four floating ledges and spikes. A sprite hero runs and jumps through it past six coins, with parallax hills and sky behind, all seen through a pixel-perfect orthographic camera.
Controls
| Input | Action |
|---|---|
| A / D, Left / Right | Run |
| Space | Jump; press again in the air for the double jump; hold for a higher jump |
Rebind them in Assets/Input/IMC_Default.inputcontext.
How it is built
Movement comes from the Platformer Kit Feature or Kit and the 2D parts from 2D Sprites and Tilemaps; Config/Features.ini enables both.
| Entity or asset | What it does |
|---|---|
Level | A Tilemap entity for Level1.tilemap. The Ground layer collides because the tileset flags its tiles Solid, and the Ground terrain auto-tiles it. The Hazards layer holds spikes and animated water |
Camera | An orthographic, pixel-perfect Camera with Camera Follow 2D: dead zone, look-ahead and bounds |
Hero | A Flipbook with a Sprite Follower. It mirrors the character and plays idle, run, jump or fall from how it moves |
SkyFar, Hills1 to Hills3 | Sprites with Parallax; the hills wrap so they never run out |
Coin1 to Coin6 | Flipbooks |
BP_Platformer2DPlayer | A Platformer Kit character with its capsule hidden (bodyVisible off) and its own side camera off (spawnCameraRig off) |
Make it yours
- Select
Level, switch the viewport to the Tile Palette mode and paint. The ground terrain picks the edge tiles. - Replace
hero.png,tiles.pngand the other sheets with your own of the same layout, or slice a new sheet with Slice Into Sprites in the Asset Browser. The generated art is a placeholder. - Add a flipbook state for a new animation in the
Heroentity's Animation States list and name it in the Sprite Follower. - Tune run speed, jumps and coyote time in the native defaults of
BP_Platformer2DPlayer.
Related
Engine sources
This page describes behavior implemented in these files of the engine repository, checked against commit 65e34cc4a.
- Templates/TP_Platformer2D/README.md
- Templates/TP_Platformer2D/Config/TemplateDefs.ini
- Templates/TP_Platformer2D/Config/Features.ini
- Templates/TP_Platformer2D/TP_Platformer2D.mproject
- Templates/TP_Platformer2D/Assets/Levels/Platformer.tileset
- Templates/TP_Platformer2D/Assets/Levels/Level1.tilemap
- Templates/TP_Platformer2D/Assets/Blueprints/BP_Platformer2DPlayer.vscript
- Engine/Features/Sprites2D/Sprites2D.mfeature
- Engine/Kits/PlatformerKit/Api/PlatformerKit/APlatformerCharacter.h
- Engine/Kits/PlatformerKit/Api/PlatformerKit/APlatformerPickupActor.h
- Engine/Kits/PlatformerKit/Api/PlatformerKit/APlatformerPatrolActor.h
- Engine/Kits/PlatformerKit/Api/PlatformerKit/APlatformerGoalActor.h