В этом уроке ты узнаешь:
- Лучшее использование встроенного поведения
- Переключение анимации: стоит > бежит > падает ...
- Тест на прогресс и премиальных балов
Строительные блоки - объекты для вставки
В игре платформере есть два вида объектов: Solids и Platforms.
Solids are obvious: they form the floors and walls that restrict players' movements. Platforms have a name which might confuse you initially: rather than being the platforms on which players stand and fight and run and jump, they're the objects that do the standing and fighting and running and jumping.
What's so great about Platform objects in Construct 2 is that you get all their basic behavior that you'd expect, without your having to do a single bit of programming:
- When you press the left and right arrow keys, Platform objects move right and left (you can change these keys, say to 'A' and 'D', if you like, or replace them with touch gestures on mobile devices).
- When you press the 'Shift' key, they jump (again you can change this key or substitute a touch gesture).
- When they've not got a Solid object beneath them, they fall.
Part 1: Beginning the build
I'm assuming you've worked through the 'Beginner's guide to Construct 2', so I'll try to avoid repeating what you've already learnt from it.
Constructing the playing layout
To get you off to a flying (jumping? running?) start, I've put together a very basic layout. Download it here and it'll be the foundation for this game:
Here's what you see on the layout:
- Four floors at different heights and with different lengths, so that the gaps between them become increasingly harder to jump. Click on them and you'll see that their Object type is 'Flooring'.
- Walls on either side. Click on them and you'll see that their Object type is 'Wall'.
- A player on the lowest floor (Tim by name, from the highly acclaimed platform game Braid - its graphic artist, David Hellmann, has generously made images freely available).
Tim's Object type is Player. But look under 'Object types' in the Project Bar, and you'll see that 'Player' is shown as a simple blue rectangle. And underneath it is another Object type named 'PlayerImages', looking just like Tim. Why this separation into two objects?
It's because the Manual advises: "For the most reliable platform movement, it is recommended to use a invisible rectangle sprite with no animations with the Platform movement. Then, the animated player object can be positioned on top of that.Otherwise, the changing size and collision polygon of the object as its animation plays can interfere with the Platform movement's floor, wall and slope detection, causing a shaking or glitchy movement."
Our invisible rectangle sprite is the Player object - click on it in the Project Bar, and under 'Object Type Properties' on the left, you'll see that its 'Initial visibility' is set to 'Invisible'. This is what will be moved by our actions and pinned to it will be the PlayerImages object, with a size and collision polygon that change as its animations play, and consequently giving unreliable detection results. Look closely at the layout, and you'll see that Tim is standing within the blue border of the Player object (helpfully visible on the layout, but invisible when the game runs).