Control mirror settings for multiple instances

0 favourites
  • 3 posts
From the Asset Store
Creepy Sprite Font suitable font for your Dark/Horror/Halloween games.
  • I'm having trouble with 3 enemies that overlap each other, whenever that happens, each enemy sprite gets mirrored/not mirrored.

    I have the code working fine when the enemy are not overlapping each other. If you guys can check the capx, its on Line 7.

    EDIT: My code is based on the enemy collision box to support multiple sprites with Platform Movement to simulate AI, not Custom movement. That is why i cannot delete the Enemy Collision Box.

    dl.dropbox.com/u/101797089/enemies.capx

  • Before giving you the answer~

    I would like to explain some basic structure of real coding~

    I think this will help you on C2 too~

    You have an event as below:

    If enemy is overlapping solid && For each enemy && Enemy direction = 1~

    "For Each" doesn't work within "&&" or "||" block in real code~

    You must declare "For Each" first before doing any actions~

    For example:

    For each enemy~

    ----If enemy is overlapping solid~ Do something~

    Same "For each" doesn't need to declare twice~

    You have a code as below on line 7:

    For each enemy collision box~

    ----If job1 is overlapping enemy collision box~

    -&&-For each enemy collision box~ <-- Declared twice

    -&&-For each job1~

    From event above, you declared "For each" within "&&" statement~

    In real code it will return compile error~

    In additional~

    Remember to pay attention on timing of events~

    Does the trigger run 1 frame or every frames~

    Sub events are important~

    You must put your events into correct sub-places~

    In order to execute correctly~

    That's it. Hope you learn something on this~ ^_^

    I cleaned up your file and this is maybe what you want:

    Deleted another wall, only yellow wall left~

    Deleted the "enemy collision box"~

    Adjusted job1's collision into "enemy collision box" shape~

    Instance variable for yellow wall:

    var wallSide = <varies>;   // Detect if it is left or right wall.

    Duplicate the wall, name the variable into "left" or "right"~

    Instance variable for job1:

    var moveSpeed = 200;       // Job1 moving speed.

    Behavior for job1:

    Custom Movement~

    On start of layout:

    Set job1 custom movement (Horizontal) speed to job1.moveSpeed~

    For each job1:

    ----If (job1 is overlapping wall)~

    --------If (wall.wallSide = "left")----{Set job1 to not mirrored;

    ----------------------------------------Set job1 custom movement (Horizontal) speed to job1.moveSpeed;}

    --------If (wall.wallSide = "right")----{Set job1 to mirrored;

    ----------------------------------------Set job1 custom movement (Horizontal) speed to -job1.moveSpeed;}

    Another suggestion:

    I have a habit to store some values / strings into variables~

    Instead of typing it directly into events~

    Because it's easy for tweaking in the future when you have a bunch of codes~

    That's it. Hope it helps. Good luck~ ^_^

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the reply AkiraWong!

    You gave me a lot of good helpful tips that i will definitely use.

    My code is based on the enemy collision box to support multiple sprites with Platform Movement to simulate AI, not Custom movement. That is why i cannot delete the Enemy Collision Box.

    If you can provide a capx for the changes you have made, that would be very helpful.

    Thanks a lot!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)