How do I create an object from a specific family ?

0 favourites
  • 4 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hi.

    I'm trying to create a function to swap some elements in my game.

    Basically, I currently have this "obstacle" family :

    wall 1

      name = "wall" type = 0

    wall2

      name = "wall" type = 1

    tree1

      name = "tree" type = 0

    tree2

      name = "tree" type = 1

    rock1

      name = "rock" type = 0

    rock2

      name = "rock" type = 1

    My function would do this : for each 'obstacle' on the layout, replace it with an 'obstacle' having the same name and "type = 1"

    Any idea about how to do that?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you can publish the CAPX will be easier to analyze. Maybe you could use frames or animation to change images. If you need to use the variable "type" for some more actions, set the same frame number to this variable and call it in AnimationFrame action (family > Set animationFrame to type)

  • Hello,

    Thanks for your reply.

    I'll publish a file in a few hours.

    I don't want to use frames or animations, because this kind of element swapping will be available for other and more complicated stuff like enemies (replacing an enemy by another ; same X and Y positon, same animation and same animation frame, etc), which will have their own animations like walk, attack and so on.

    A few years ago, I had the same kind of issue for my shoot'em up, when I wanted to spawn a specific element of a family. The only solution I found on this forum was this one :

    spawn a random object in the family : if not the wanted object (for exemple if variable name != laser if I want an object of 'laser' type), destroy the newly spawn item and try again. If the wanted object, just break the loop.

    That's ugly and slow (especially with a lot of objects in the family), but it kind of works.

  • Hi again :

    http://canapin.com/construct/test/test_swap.capx

    So, I'd like a function which swap every object having "variante = 0" in the decoration family with other objects in this family which have the same name (each door have a variable 'name' = 'door' and same for the trees) and "variante = 1".

    The purpose is beeing able to switch a lot objects with a single function (for example, if I have 50 regular objects and 50 "alt" objects in decorations family...).

    I tried some things but I didn't managed to do it.

    edit :

    I think I'm moving toward a solution. I used the container functionnality. Each element is linked to another element. These two linked elements are on different layers but have the same position. I'll prevent the game to interact with objects on this background layer and I just have to create a function to make them switch their layers, which should be not very difficult.

    http://canapin.com/construct/test/test_swap/

    The moving background A is linked with the red shape B via the container functionnality. They both have the same X Y coordinates.

    The green tree J is linked with the blue tree K. They also both have the same X Y coordinates.

    A and K are on the background layer. They could be invisible too. When I interact with the drag'n droppable grey square, I collide only with the elements on the front layer.

    So, that's it : if I'm able to swap the element layers, that should do the trick. Sorry if my explanations are bad, I'm not that good in english.

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