Advice needed on best practise in bigger projects

Get help using Construct 2

Post » Wed Jan 04, 2017 10:29 pm

hello,

I was wondering for a best practise for the following example:

Player (sprite) has animation Idle and Running.

Example:
if sees enemy: play animation running
if does not see enemy: play animation idle

If player is running: play animation running
if player is not running: play animation idle


Now I think: I also want a hit animation.
The only way I know to edit the code (and insert the hit animation) is to use global or instance variables to make a clear seperation of what a player is doing and when an animation to play.

I would add:
if player overlaps SomeSprite: play animation hitting.

My example from above would change to:
if sees enemy, and does not overlap SomeSprite: play animation running
if does not see enemy: play animation idle

If player is runningand does not overlap SomeSprite: play animation running
if player is not running: play animation idle


By adding something new in the same "area", I have to edit all existing events that have to do with this. (because it effects eachother)
Can this be done easier/more efficient?
B
28
S
6
G
7
Posts: 678
Reputation: 5,676

Post » Thu Jan 05, 2017 2:04 am

Use a Global Variable to determine what animation is being played as a trigger/

Global Variable: Player.Action

Add that as a condition to your event:

if sees enemy: play animation running
if does not see enemy: play animation idle
Set Player.Action to 1

If player is running: play animation running
if player is not running: play animation idle
Set Player.Action to 2

Now you can define which action is happening for other events.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Thu Jan 05, 2017 7:20 am

Thank you, I will look into that.
B
28
S
6
G
7
Posts: 678
Reputation: 5,676


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 49 guests