How do I change the image of a sprite object on creation

Get help using Construct 2

Post » Sun Nov 22, 2015 8:07 am

Hi,

I am trying to create new sprite objects just off to the side of the layout. They travel across the layout to exit on the other side. But as I want a stream of sprite objects, once each new object gets to a point inside the layout a new one is created off screen which then travels across to trigger the creation of another and so on. As I need each object to inherit a different image file's size and colours, I need to access the new objects unique id and give it a new image. The problem is I don't know how to do that.

Can I get some help please?

Here's the code so far
https://www.moxtra.com/v/CAEqBW15NmluehdCVXdEQmtNOXBYMDhUTm1hNjRnYUtEMIABEZADFA
B
10
S
2
Posts: 50
Reputation: 1,100

Post » Sun Nov 22, 2015 12:11 pm

Changing the image of a sprite would be as simple as attaching an action to set frame or animation..

If you want to create a sprite with the same animation you could try something simple as this

sprite on destroyed
(local variable text)
> set local variable text to :sprite.animation
> system create object sprite
> sprite set animation: local variable text

Example
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Nov 22, 2015 9:21 pm

Hi and thanks for the reply LittleStain,

I would do it this way only I need the image files to be loaded as generic items. Say for example I just wanted the file names to remain the same always but not the images. So any image can be called 001 and all I need do is load new images into my file folder without having to open the project up in C2. Though I will look into something similar to your example.

Thanks for your help.
B
10
S
2
Posts: 50
Reputation: 1,100

Post » Mon Nov 23, 2015 10:25 am

I'm sorry, but I don't understand what you are trying to do..
Maybe "load image from url" is your aim?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Nov 23, 2015 8:12 pm

Hi,

I am already loading an image from an URL. I need to load a different image for each consecutive create object instance. I am wanting a steady stream of images flowing across the screen with a different image each create object occurrence.

Cheers
B
10
S
2
Posts: 50
Reputation: 1,100

Post » Mon Nov 23, 2015 8:22 pm

Image
if you have image "1.png"
or
"something"&PNG&".png" .........something1.png
Image
B
64
S
23
G
7
Posts: 1,481
Reputation: 10,823

Post » Mon Nov 23, 2015 11:45 pm

Do so decided, is this what you wanted?
B
29
S
9
G
3
Posts: 280
Reputation: 4,187

Post » Tue Nov 24, 2015 5:14 am

Thanks korbaach,

I'll test this but I am spawning/creating a new instance of the intial sprite. I need to have a different image loading on each instance.
I tried doing this by using the UID but it just changes the lot of them to the next image rather than giving me the sprite requested for the separate sprites.

https://www.moxtra.com/v/CAEqBXFmOXR5ehdCVXdEQmtNOXBYMDhUTm1hNjRnYUtEMIABQpADFA


Cheers all
B
10
S
2
Posts: 50
Reputation: 1,100

Post » Tue Nov 24, 2015 10:05 am

lukeo25 wrote:I need to have a different image loading on each instance.
I tried doing this by using the UID but it just changes the lot of them to the next image rather than giving me the sprite requested for the separate sprites.
Image


The only way to do that... is to use diffrent frames

Image
Image
B
64
S
23
G
7
Posts: 1,481
Reputation: 10,823

Post » Tue Nov 24, 2015 9:08 pm

Thanks Korbaach,

Now that makes perfect sense.

Cheers
B
10
S
2
Posts: 50
Reputation: 1,100


Return to How do I....?

Who is online

Users browsing this forum: jkmalau, MoscowModder, terence951, vegapomme27 and 9 guests