{Solved} Change an object image/sprite in event sheet

Just started using Construct 2? Post your questions here

Post » Thu May 08, 2014 10:09 am

Hello,

Forgive me if this is such a simple question, i have searched the forum and used search engines to try and find the answer with no luck.

I am making a platform game where i would live to change the sprite using event sheet after a button is pressed. So if you press SPACEBAR then the sprite will change the hero into a hero with sword sprite i have made, for a few seconds, then revert back.

Then i can add collision events where if the enemy if the enemy collides with the non-sword sprite the hero dies. And if the enemy collides with the sword sprite the enemy dies.

Thanks for reading,

Phil
Last edited by PhilWilky on Thu May 08, 2014 9:03 pm, edited 1 time in total.
B
2
Posts: 5
Reputation: 175

Post » Thu May 08, 2014 10:44 am

Hi @PhilWilky

I believe the best way to do this is through an animation. First insert frames in the sprite with all the heroes and change the speed to zero. Then put an event to change the frame of this sprite each time you press the space key.

First add the "keyboard" object.

Event: on "space" pressed
Action: Sprite>> Set animation to frame 1

Good lucky!
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Thu May 08, 2014 11:12 am

Hi @RenatoB

Thanks for the help that works perfectly.

It changes to attack sprite on frame 1 then waits two seconds then reverts back to original sprite frame 0.

if people were to want help on doing this then this is the working event sheet.

Image

Another big thank you RenatoB.


Phil
B
2
Posts: 5
Reputation: 175

Post » Thu May 08, 2014 11:35 am

RenatoB wrote:Hi @PhilWilky

I believe the best way to do this is through an animation. First insert frames in the sprite with all the heroes and change the speed to zero. Then put an event to change the frame of this sprite each time you press the space key.

First add the "keyboard" object.

Event: on "space" pressed
Action: Sprite>> Set animation to frame 1

Good lucky!



Looking at the collision. I am having trouble connecting 'is animation playing' event to get collision when the sword sprite is showing.

In other words i can connect player collision with enemy no problem but trying to connect the animation frame with collision seems to be hard.


Thanks,
Phil
B
2
Posts: 5
Reputation: 175

Post » Thu May 08, 2014 2:35 pm

Hi @PhilWilky

I do not know if I understood your needs, but if the issue is collision when change the frame, you can resolve this by setting the boundaries of the collision polygon.

Open the "Edit image" window and click "Set collision polygon", then click the right mouse button on one of the points and choose "Guess polygon shape" and make adjustments as necessary.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Thu May 08, 2014 3:39 pm

RenatoB wrote:Hi @PhilWilky

I do not know if I understood your needs, but if the issue is collision when change the frame, you can resolve this by setting the boundaries of the collision polygon.

Open the "Edit image" window and click "Set collision polygon", then click the right mouse button on one of the points and choose "Guess polygon shape" and make adjustments as necessary.


Hi,

Its not that hrm.

okay so now i have one object and two sprites on that object. Now i need some how to test which sprite is active. So when the enemy collides with the hero object i need the level to restart, now that's easy. But adding a collision to the hero with sword is not working i have tried.


Sorry cannot think of anyway to make this clearer.
Phil

adding the event "'is animation playing" to see if the sword hero is active then adding a collision event. Then destroy enemy sprite. but this is not working.
B
2
Posts: 5
Reputation: 175

Post » Thu May 08, 2014 4:11 pm

@PhilWilky

It's easier when we can see the CAPX, but I think I get it now. You need to compare the frame when occurs collision between the sprites.

Event: Sprite (hero) >> On collision with another object (on collision with enemy)
Subevent: Sprite (hero) >> compare frame (= Animationframe hero / sword frame number)
Action: Destroy enemy

I hope now your problem has been solved.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Thu May 08, 2014 9:02 pm

@RenatoB

Hi sorry i did not know i could do that. Yea that as worked thanks did not know about sub events so great to know. Thanks again for all your help.

This is it in full if anyone wants to see.
Image

Phil
B
2
Posts: 5
Reputation: 175


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests