0 Favourites

How do I Place multiple objects with different animations

  • Hi!

    For my problem i will use this example.

    I have a level select page ( for Android ).

    Now, i am looking for the best way to do this.

    Every level got it's own object / image ( level 1, level 2, level 3 etc. )

    Now what i can do is creating 10 images for all 10 levels and put 10 objects on my layout.

    Yet i think this is a waste of memory and objects.

    Is it possible to use 1 object with all 10 images as animations?

    What i had in mind that didn't work.

    One object.

    The object has animation frames: 0,1,2,3,4,5,6,7,8,9,10

    The object has a instance variable named: animationID

    I give every placed objects its animationID as: 0,1,2,3 etc.

    Than on start of layout, set animation to: animationID

    This actually doesn't work since i can't do the last step.

    I know this is wrong but i need some idea to reach that goal.

    Thanks in advance!

  • You've got the right idea. Must just be an issue with the execution.

    Animation names are strings, even if they're numerical, so make sure that your animationID variable is set to the string type, rather than integer. Otherwise, if you really want them to be integers (maybe you need to work with the numbers mathematically for example), then in your action set the animation to str(animationID).

  • Hi.

    Finally i got the right idea about something !

    Well my problem is that i cant use animationID for some reason.

    I got the instance variable on the object as Type: Number

    With the "Set animation" action i can not use animationID as refference.

    Any idea why? Or what i am doing wrong?

    Thanks again!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • It is possible! You said you're using the same background and objects for each level right? And when the player goes to a level, you want to set the animation of those objects accordingly?

    You would just have to do something like

    On levelbutton.click

    • Go to level levelbutton.number
    • Set bacground animation frame to levelbutton.number
    • Set objects animation frame to levelbutton.number

    You'll might have to pick the objects using something like "System - pick all objects" so all their animations are set to the same frame as the level you picked.

  • Thanks for your reply!

    Actually i use the same object for different images.

    I think i can make myself more clear now.

    I got a object with all different frames ( not animations my bad there! )

    I made this image to make it a little more clear.

    As shown in the picture i got only one object with all levels as frames.

    I place the object multiple times in my layout.

    Now, on start of layout it has to use its instance variable "levelid" to know what frame it would show.

    But also as you can see, with the "Set Frame" action i can't use "levelid" as refference.

    Any idea how to do this idea?

    Thanks again!

  • Thanks for your reply!

    Actually i use the same object for different images.

    I think i can make myself more clear now.

    I got a object with all different frames ( not animations my bad there! )

    I made this image to make it a little more clear.

    As shown in the picture i got only one object with all levels as frames.

    I place the object multiple times in my layout.

    Now, on start of layout it has to use its instance variable "levelid" to know what frame it would show.

    But also as you can see, with the "Set Frame" action i can't use "levelid" as refference.

    Any idea how to do this idea?

    Thanks again!

    you should use the name of sprite to reference the correct variable.... in your screenshot you try to set the frame with a global variable

    use self.levelid

  • hi Allardje,

    find below attachment.

    hope this is solution for u.

  • Piuu thanks!

    I think your script works once you change the Variable1 = 3 to Variable 1 = self.Variable1!

    Let me try after my lunch!

    Will post back, thanks!

  • Also with self. i can only use the things like:

    Angle

    AnimationFrame Etc..

    There is no way i can use my instance variable

    I use this method with my games...

    try this capx

  • Hi all,

    I've got to admit.. I'm a d*ck again....

    I see now that i do not know Construct 2 very well..

    I see that you can set a Initial Frame.. Thats actually all i need...

    Sorry for my dumb mistake and for your time.

    Though thanks for all the help!

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