Help with Instance variables and on-touch

Get help using Construct 2

Post » Fri Apr 05, 2013 5:01 am

There is an important distinction between your project example and my own that may be of note. In your example you have your sprite object with 5 animations and each animation has 1 frame. In my project My LvlSel Sprite object has multiple animations as well...but each animation has 11 frames. In my set up when the player touches the designated object (the "Foreward" sprite object) Animation 1 runs through all 11 frames...then on the next touch it runs through all 11 frames of the 2nd animation...and so on. What I need now is for a player to be able to touch the "Reverse" object and have the animation (which ever animation of the LevSel object is CURRENTLY on) run in reverse. Then if the "Reverse" object is touched again run the proceeding proceedinganimation in reverse. Inversely if the player touches the "forward" object the LvlSel sprite runs the animation in forward order from where ever it left of last.

I know I need some kind of code logic that 1st checks to see what the current animation just finished playing. Then 2nd, depending on what animation of the levSel sprite object it is on it runs another animation of that sprite object in either forward or reverse depending upon which object is touched (The "Forward" sprite object or the "reverse")
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Fri Apr 05, 2013 6:39 am

I made a quick demo that represents what I am trying to do.

I left my latest attempt to run the animations in reverse in place but toggled disabled and I set it up as an on click rather than a on touch in case you don't have a touch screen device. I know you can easily replace that condition but you are helping me so I figured I could make it easy.

https://www.dropbox.com/s/akuq9oc9lijhukc/Touch_Click_Animation.capx
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Fri Apr 05, 2013 9:01 am

Here are few posts about reversing animations:

http://www.scirra.com/forum/play-animation-in-reverse_topic48894.html
http://www.scirra.com/forum/need-to-reverse-animation_topic55826.html

There are various solutions for the problem. Here is one implementation, hopefully it's close what you were looking for: Animated level select

Mouse clicks 'simulate' touch events by the way, so you can use touch object even if you use a mouse. :)

If you wish to include me in the credits, I have no objections, would be an honor :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Sun Apr 07, 2013 5:40 am

Your example is fantastic! It does far more to help me understand the specific programming nature of my issue than the posts but the posts help me understand the terminology so thank you on both fronts.

I still have a long way to go to understand the expressions because I come from an Art background in my professional Game development experience rather than a programming. Things like "self.AnimationFrameCount-1" make sense when I see them but knowing how to create them still eludes me. My hope is that will come with time but seeing those expressions in a layout as it pertains to my specific needs are spectacular and I very much appreciate your efforts.

On the mouse event...I realized that after I posted it but thanks for stating it as it may be of use to another reader at some later date.
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Sun Apr 07, 2013 5:51 am

Now if I may be so bold I would like to ask how I might prevent the animations at the beginning and end of the sequence from repeating. In our example file we have the steering wheel with "animation 3" (or animation3 in the sprite animations listing). If the player is at the end of the available animations I would like a click on the right arrow to do nothing (at this time it runs the animation again)...however I would like to preserve the functionality of going in reverse from that point. Inversely, if the player is on "animation1" a click on the left arrow should do nothing (presently it runs "animation1" in reverse) but the player is free of course to play the animation forward if they click the right arrow.

Concerning the credits would you like just your Forum user name or your real name in them? If you would like your real name you are free to PM me on that. Your assistance on this has been invaluable and giving and to those who have helped me is the least I can do. If you ever feel like making some money on the side PM me on that too...my company s small but I do have a budget for contractors.
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Sun Apr 07, 2013 6:17 am

For the record I have figured out how to do this for the Last animation in the series by using an event where the Sprite has a compare frame of 7 (the number of frames in the animation) followed by a sprite stop animation action but I can seem to figure out how to do it one the 1st animation of the sprite.
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Sun Apr 07, 2013 6:55 am

Something else I am noticing is that once I reach the end of the sequence (the last animation: "animation3) clicks forward get recorded...even though there is no animation to go to next (or after my latest event addition the animation stops)the click is retained in the "Add 1 touches" action associated with the "Touches" instance variable...and the back arrow must be click an equal number of times for the previous animation to even start running in reverse. Ideally, for my purposes the "Add 1 touches" would have a condition that prohibits the recollection of touches that would exceed the total number of animations associated with the sprite object. That way...if the player is on the last frame of the last animation in the series not only does it halt the animation from playing again it no longer records the touches in the "Add 1 touches" action so the number of touches on the forward sprite object from that point need not be repeated an equal number of times on the reverse sprite object.
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Sun Apr 07, 2013 7:48 am

I updated the link I posted earlier, there is now simple comparison to check that touches variable stays within amount of levels in the game. Hope this helps. :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Sun Apr 07, 2013 8:27 am

Very cool...I had to make one slight adjustment to the global variable (from 3 to 4) as when it was set to 3 it wouldn't actually play animation3 prior to halting the forward animations. If I am understanding this correctly...if I were to add animations to the sprite object I would simply increase the global variable a corresponding number of times.

Does that sound about right?
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Sun Apr 07, 2013 9:22 am

[QUOTE=E2GameStudios] Very cool...I had to make one slight adjustment to the global variable (from 3 to 4) as when it was set to 3 it wouldn't actually play animation3 prior to halting the forward animations. If I am understanding this correctly...if I were to add animations to the sprite object I would simply increase the global variable a corresponding number of times.

Does that sound about right?[/QUOTE]

That is correct. Sent you pm by the way :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: YoHoho and 13 guests