My animations aren't working properly

Get help using Construct 2

Post » Thu Oct 06, 2016 8:22 pm

Hello,

I have some problems concerning animations in construct 2.

There is my situation : I have a ship than can shoot laser. This ship has 3 colors which represent 3 states : Yellow red and blue. (It's an Ikaruga like for theses who knows).
Besides this, there is asteroids that are blue or red. So depending on the states of my ship the player gains more or less points.

Yellow state is 1 point no matter the color of the asteroid.
Blue stat is 2 for blue asteroid and 0 for red. Reciprocal for red.

But this isn't my problem (yet, at least). What I want is when the player press "shit" the ship become blue (done) and when i press ctlr the shipe become red (done aswell).
BUT. On this I have one big problem and maybe something to optimise the gameplay.

FIRST PROBLEM : The ship become red or blue but the laser is still yellow, no matter what. (In the debug i've saw that the old laser (already shooted) chance states but not the new one).
So i need to know how to put red or blue for my laser, dependings of the color of my ship (blue for blue / red for red ofc).

Then for the optimisation i'm wondering if it's possible to push only ctrl to change the color of my ship (tried but ain't working in the way i found).

There is some screens to make helps easier for you.
The settings of my frames. Working in the exact same way for the lasers. (frame 0 = red ; frame 1 = yellow ; frame 2 = blue in the same animation)
Image

And now my event settings. I have the space key to shoot (it stop the animation so it stays yellow at the beginning since my yellow isn't the last frame). And I have the shit / ctrl pressed where i try to treat my ship + laser in the same way, it works for the ship but not for the laser, so i'm quite lost :/
Image

---------------------------------------

EDIT 1 (06/10) :
I've worked on something else to wait people to answer and i'm like mind fucked.
I wanted to put an explosion animation so i've added an animation named explosion and putted multiple explosions in frames so this case is settled. I've added it on my event, when my sprite is destroyed it is supposed to play the animation "explosion" like we can see on screen, but when i'm trying to play it, nothing happening, so i'm lost :/
Image

Thank you very much
B
5
S
1
Posts: 30
Reputation: 441

Post » Fri Oct 07, 2016 12:30 am

I'm having some trouble understanding your issue but with the code you have outlined in red, try using sub events.

Keyboard > ESpace is Down
(sub event) > Every 0.2 seconds > Ship > Spawn Laser

( create a second condition)

Laser > on created > System wait 0.2 seconds
> Destroy Laser

The explosion problem is your destroying it before the animation can play. It should be handled in the 3rd line:

Asteroid > On collision with laser > asteroid > Spawn Explosion
> destroy > asteroid

The explosion needs to be a separate sprite and needs to be spawned just before the asteroid is destroyed.
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,293

Post » Fri Oct 07, 2016 12:35 am

Yeah well, it's hard to tell without a capx to try and see, but hey why are you stopping the animation after each frame change -- it's easier and safer just to set the animation speed (first image, under Animation 'Default' properties) to zero, and then you can just set the frames at ease.
Im not sure if that would fix you tho, you may need to use some System>Loops>ForEach conditions here or there...
B
23
S
11
G
6
Posts: 181
Reputation: 5,010

Post » Fri Oct 07, 2016 4:01 am

FIRST PROBLEM : The ship become red or blue but the laser is still yellow, no matter what. (In the debug i've saw that the old laser (already shooted) chance states but not the new one).
So i need to know how to put red or blue for my laser, dependings of the color of my ship (blue for blue / red for red ofc).
--> try to compare the animation like this
STARTLAYOUT > stop all animation

if animation Red is on then spawn red laser

i dont know if this will help you
B
79
S
31
G
7
Posts: 148
Reputation: 9,179

Post » Fri Oct 07, 2016 9:12 am

@TheDom
Keyboard > ESpace is Down
(sub event) > Every 0.2 seconds > Ship > Spawn Laser

( create a second condition)

Laser > on created > System wait 0.2 seconds
> Destroy Laser


I'm not understanding this part. Doing a destroy on laser after 0.2 secs is just making my laser pop and destroy it almost right after.
For the animation it's barely good, it's working (and was such a stupid mistake x) ) but my animation is waaaay smaller than my original sprite, so we barely see it when it explode.

EDIT 1 : There is no animation problem, I've made it the way you say (haven't saw before ><), by doing a sprite and now working as hell

-----------------------------

@megalocrator

Yeah the speed sets was a better idea. I don't get why and where I shall uses the loops ? (I'm a total beginner ^^')

-----------------------------

@clarkkentnicdao

Kind of helped me since it gave me an idea which is almost working :D.

-----------------------------

For everyone

First of all there is my capx at this point drive.google.com/open?id=0B6phdwDtsxJkTXN1RnU3TUYyMDA

Then my update is, i've found the way of putting the right frame so my red ship shoot red laser, same for blue. But the prob here is the last laser shooted is always yellow, no matter how many lasers i shoot the last one (until i shoot again, then it switch to the ship color)

So i guess that's because i'm setting the animation when i press space right before it spawns like we can see there (for those who don't want to DL my capx)
Image
B
5
S
1
Posts: 30
Reputation: 441

Post » Fri Oct 07, 2016 1:17 pm

yeah, nevermind the loops! im not that good at coding :P
B
23
S
11
G
6
Posts: 181
Reputation: 5,010

Post » Fri Oct 07, 2016 3:16 pm

Image

For your code here outlined in red I don't believe it will create the desired effect.

This is checking every 0.2 seconds to see if escape button is down. It is NOT activating when escape is down and pausing 0.2 seconds. With such short time it may not be noticeable if you hold down the button. But if you were tapping the escape button and it coincided hitting in between the 0.2 seconds then nothing would be happening. Suggestion would be to have a "ready" instance boolean or something similar.

Also, I don't know what you are doing exactly, but not sure why you have the spawn a laser after setting the animation for the laser. I believe the way you have it the changing the animations of the laser will affect all of the lasers on the screen then spawn a new one that is unaffected by those actions. If you put the spawn before then the animation actions will only affect the spawned laser.
ImageImageImage
B
44
S
26
G
11
Posts: 518
Reputation: 10,502

Post » Fri Oct 07, 2016 6:14 pm

@badmoodtaylor

Suggestion would be to have a "ready" instance boolean or something similar.


Could you tell me a bit more about this ? Like i said i'm a beginner (this is my first real project) and i've never used booleans on construct 2 so i'm kind of lost :p.
And i'm very intereset of doing the best I can for this project before I have to get it back

And about the second part, yh i've changed and put the spawn before setting the animation and it works perfectly. Was kinda confused in my mind.
I tought it was setting the animation (so the colour) and then create the laser so i tought it would have been more efficient that way, should have tried both way x)

EDIT : The project : drive.google.com/open?id=0B6phdwDtsxJkTXN1RnU3TUYyMDA
From this i'm wondering a thing because i'm totally lost in the even sheet. I'm doing the scoring so I want to do some conditions like this
Code: Select all
Laser on collision with asteroid
{
if (laser.frame=blue&asteroid.frame=blue)
add score 2

else if (laser.frame=red&asteroid.frame=red)
add score 2

else
add score 1
}


I know how to do it with code but not in construct 2 so it kinds of bore me and wondering how to do it ?
B
5
S
1
Posts: 30
Reputation: 441

Post » Fri Oct 07, 2016 7:36 pm

Boolean is just a variable that can only be "true" or "false". To create an instance variable (as opposed to global variable) you click on an object and add it via the properties bar (initially on the left).

What I was implying was replace 'every 0.2 seconds' with 'ship.ready' (meaning boolean is true). Then add an action to that event that changes the boolean to false. To have it change back to true every 0.2 seconds add the timer behavior and create an action to start a timer. Then create a 'on timer' event that changes the boolean back to true. (you could use wait but will most likely lead to bugs in the future)

This variable can be helpful in the future also for when game is paused or maybe ship gets stunned or something, just have to change the boolean to false.

I understand your thinking on setting the animation before it is spawned, I kind of had the same lines of thinking at first. But remember how fast all of this can be processed but also was probably setup to actually process those actions at once.

If you want to replicate that in construct you just need some sub-events, which are visually indented and work like a nested if, and the else command, which is in the system events. The else command will fire if the command above it fails. You can have multiple conditions but the else has to be at the top of them. It will be apparent if the else command is setup wrong.
ImageImageImage
B
44
S
26
G
11
Posts: 518
Reputation: 10,502

Post » Fri Oct 07, 2016 9:50 pm

@badmoodtaylor

Fixed the first part (with boolean/shoot and stuff, perfectly working.)

But, I still have a problem with the scoring. I've tried the else stuff and it's very complicated and I don't understand.
So i've found an other way to do it. I've added variable named state into my laser and my asteroid. So when i want to score I compare the state of the asteroid and laser.
So, if laser.state = asteroid.state then it adds +2 ; if it's not equal it adds +1. The +1 thing is working but not the +2.

The good things is, I know why but I doesn't know how to fix it. When I press "shift" or "ctrl" to set the red/blue color to my ship it is supposed to change the animation of my laser and change the color, it works, but in the same event it's supposed to also change the state of my variable (putting 0 or 1 dependings of the ship color) but it's just never change and I don't get why. :/

There is a screen of my even sheet and my capx there : drive.google.com/open?id=0B6phdwDtsxJkTXN1RnU3TUYyMDA
Image
B
5
S
1
Posts: 30
Reputation: 441

Next

Return to How do I....?

Who is online

Users browsing this forum: kizlengames, Yahoo [Bot] and 6 guests