How do I Place multiple objects with different animations

Get help using Construct 2

Post » Tue Mar 11, 2014 4:03 pm

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!
B
10
S
4
G
3
Posts: 163
Reputation: 2,507

Post » Tue Mar 11, 2014 4:15 pm

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).
B
57
S
15
G
11
Posts: 912
Reputation: 12,606

Post » Tue Mar 11, 2014 4:39 pm

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!
B
10
S
4
G
3
Posts: 163
Reputation: 2,507

Post » Tue Mar 11, 2014 6:23 pm

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.
B
122
S
42
G
40
Posts: 846
Reputation: 27,994

Post » Wed Mar 12, 2014 10:49 am

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.
Image

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!
B
10
S
4
G
3
Posts: 163
Reputation: 2,507

Post » Wed Mar 12, 2014 11:06 am

Allardje wrote: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.
Image

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
B
21
S
9
Posts: 298
Reputation: 2,967

Post » Wed Mar 12, 2014 11:12 am

hi Allardje,

find below attachment.
hope this is solution for u.
You do not have the required permissions to view the files attached to this post.
B
7
S
1
Posts: 68
Reputation: 561

Post » Wed Mar 12, 2014 11:13 am

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!
Last edited by Allardje on Wed Mar 12, 2014 11:17 am, edited 1 time in total.
B
10
S
4
G
3
Posts: 163
Reputation: 2,507

Post » Wed Mar 12, 2014 11:17 am

Allardje wrote: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
You do not have the required permissions to view the files attached to this post.
B
21
S
9
Posts: 298
Reputation: 2,967

Post » Wed Mar 12, 2014 12:11 pm

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! :-)
B
10
S
4
G
3
Posts: 163
Reputation: 2,507


Return to How do I....?

Who is online

Users browsing this forum: imothep85, KTML5 and 9 guests