On Touch through an animation?

0 favourites
  • 11 posts
From the Asset Store
3 pixel charaters with over 8 animations each + animations with a gun
  • Hello everyone. This is my 1st post here so please be gentle. <img src="smileys/smiley2.gif" border="0" align="middle" />

    I have looked through and searched many forum posts to an answer to my issue to no avail so I'm finally conceding and will ask you guys for help.

    Please either point me in the direction of an answer suitable for a noob or address the following directly:

    I have a sprite animation with 30 frames in it...that sprite animation is set to the full size of the layout and I am trying to get the on-touch event to change the frame in the animation to the next one in the sequence.

    So far all I have managed is for it to change to frame 2...then it takes off and runs through the entire sequence.

    I am a ripe amateur with the event sheet so any assistance would be greatly appreciated.

    Thanks!

  • Hello! Welcome to the forums. :)

    It could be that you are simply forgetting to "stop" the animation on start of layout?

    In either case here's an example of the full answer:

    dl.dropbox.com/u/116137178/Help/HelpWithAnimation.capx

    (I can't hyperlink yet, so just copy n paste it)

  • Silkc2

    Thank you...after updating my copy of c2 (to version 121)I was able to open the capx you made for me. I was able to copy and paste the events into my project and update the reference to the animation sequence I have. After I deleted all my various attempts to set up what you have done it worked!

    However, I am hoping to understand how to set this up on my own as I would imagine community members such as yourself would grow very tired of essentially writing code for me which I turn around and adapt to my project. So if I may be so bold I would ask for some basic tutelage on these events but realizing that a nebulous "how did'ja do dat" would not reflect my aptitude or my regard for your selfless efforts on my behalf I will try to be specific:

    I see that you started the event sheet for the layout with a System Event that references the (sprite) animation and then set up an action of "Stop on load". My understanding would be that this effectively halts the animation on frame 1 until it's told to do something else and that makes sense to me. There are details about that process such as the event sheet's reference to the layout (meaning the necessity to have the sprite inside the layout if the event sheet references it) or the relationship between an event system action to stop the animation vs. setting the spite's animation speed to "0" or setting "Loop" to no that elude me but I can probably figure that out own my own through trial and error.

    Where I am quite lost is when we begin with the on-touched action: Here the on-touch event is tied to the sprite object (the animation) then somehow you have what I believe to be called an expression (correct me if I am wrong) tied to the sprite animation BUT nestled within the On-touch event. My experimentation would indicate that this a "condition" added to the event via right clicking on the event. I say "indicate" because often what I have concluded about the logic in c2 is not correct. *I am confident that is a reflection of my total lack of programming experience rather than any error on the part of the fine makers of the product. Anyway, within this condition you have an expression that makes a comparison (of =Equal to) to a number "Self.AnimationFrameCount-1" followed by a conditional system else that appears to dictate that the frame number be set to "Self.AnimationFrame+1" and THAT Sir (or Ma'am) blows my mind .

    The problem is that I wouldn't have known A) to set up the conditions inside the event B) to reference the sprite in that condition or C) how to formulate the syntax used for the number fields.

    Maybe the logic I am struggling with here is covered in some undiscovered tutorial or is simply a reflection of everyone else's experience with coding in general but I am anxious to understand how you knew to set that string of Action/events. If I can grasp and employ that information then I can probably work out how to do some more complex things with my project such as having the sequence stop...letting another sequence be run within the layout (using the same ontouch logic)...and once that sequence is finished having the original sequence continue to completion (effectively ending the layout and redirecting the user to another layout).

    I sincerely appreciate any additional time you spend enlightening me on this even if it is only to point me in the direction of a tutorial that covers the logic behind the event sheet.

    Respectfully,

    Matthew

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think I may have found a source of information to answer my own questions:

    scirra.com/manual/44/event-sheet-view

    and

    scirra.com/manual/75/how-events-work

    I'll be sure to drop in on this thread if I am still left wanting on the specifics of my situation.

    Thanks!

  • All I'm doing on that if statement is making sure the frame number I set can't go above the max frames in the animation (3).

    The AnimationFrame property is 0 based so my three frames are 0, 1, 2.

    AnimationFrameCount, like any count field will return the literal number of items, so it'll tell me there are 3 frames. I can offset this by -1 to ensure I'm checking the last actual frame number has hit my max frames.

    In this case AnimationFrameCount-1 = 2.

    If my sprite is already on frame 2, I don't want to add 1 as frame 3 doesn't exist. So instead I go back to the start i.e. frame 0.

    In any other situation I'm happy to add 1 to the frame, so I just catch that in an ELSE.

    This approach means my code will work no matter how many frames are in my animation. I never use hardcoding if I can help it.

    You should also go through the tutorial if you haven't yet, it's a good start.

    scirra.com/tutorials/37/beginners-guide-to-construct-2

  • Silkc2

    So "0 based" simply means that the animated sequences begin with 0 rather than 1 (because when you import frames it begins with 0...then goes to 1,2,etc).    Got it.

    When you say "if statement" I assume you are referring to the condition where you have an expression that makes a comparison (of =Equal to) to a number "Self.AnimationFrameCount-1" but I am confused when you talk about offsets and checking the last frame...though I have yet to actually encounter an "if" when looking through the system or object events. However, before I dig too much into that I would like to validate my understanding on the function of the even sheet as a whole. Would I be correct in saying the Event Sheet is where the user articulates how and when the imported assets and native objects (to the program) are presented and manipulated upon the execution of the layout? And further, that terms like "if statement" or "Else" and "While" refer to the logic that allows the user to communicate to the program how and in what order those objects should be manipulated? Finally, that the code is read and executed from top to bottom unless a loop is put in that dictates the program repeat some previously dictated action?

    *That question may make it look like I know more than I am leading on but that paragraph was the end result of about 20 minutes of research, careful thought and selective phrasing but ultimately is a real set of questions as I have found that often my conclusions are only partly accurate and the component I am missing is vital to a true and accurate understanding of the topic.

    The reason I elected to request validation on those things is so that I can have the proper frame of reference for some of your other statements. For example: You say "if my sprite is on frame 2"...does that refer to where the sequence left off during the execution of the events on the event sheet or rather does that refer to where it is set to start in the properties of the sprite object under "initial frame" (or both)?

    If you failed to designate to Animationframecount-1=2 would c2 simply continue to try to add frames even though the animation (in your case) consists of a total of 3 frames? Why is it necessary to designate NOT to try to go to frames that do not exist? Or does the "Else" statement serve only to create a loop where the sequence repeats itself indefinitely upon (in this case) an ontouch event?

    Finally, when you say "hardcoding" what does that mean and what would your approach be called in programming terms? Dynamic coding? Can you provide a simple example of both methods (or refer me to an example)? Does hardcoding refer to writing a series of events/conditions/expression that facilitates a beginning to end execution of a layout independent of the nature of an object or it's relative complexity (like the number of frames in an animated sprite sequence)?

  • The important thing to understand is a "game loop" - what happens & when per frame of the game running - usually broken down into "update" where you trap events such as key presses, and "draw" which is where you draw the next frame onto the screen with all your associated sprites.

    Construct thankfully simplifies the concept for non-programmers, so in a nutshell you just have to know that the event sheet is looked at once per frame, events are read in order from top to bottom, and html5 games typically run at 40-60 frames per second.

    If you want something to happen every frame, such as moving a sprite around, you'd use "every tick". If you only want something to run on a condition, then there's loads of different things you can do - me checking the sprite's frame is just one example of a condition.

    Following the tutorial I linked should make you more than familiar with the above.

    There isn't an opposing word for hard-coding, just know that it's frowned upon in the programming world.

    In this case I could have hard-coded the number "2" on my max frame check, rather than "animationframecount-1". That would be typical hard-coding and would break if I added more frames to the animation.

    As for what would happen if you try and set the animation to 3 and above.. try it yourself! Construct2 is a sandpit, grab your shovel. I suspect it would simply keep the previous/last known frame i.e. frame#2 as it doesn't understand the next instruction. In other programming languages which are more strict this would end up throwing an exception.

  • Hey silkc2. I did manage to terminate the loop (seems I lack the rep to reply to your message). I do however have a new problem I am hoping you can help with. Please check out my new post on sequential animations I could really use your clarity!

  • how about Loop thru animation on each touch..it posible..?

  • phepot

    If you are asking if you can play the whole animation on touch it's easy.

    this event would do that:

    on touched object - play animation

    but I guess you are trying to do something else.

  • yes on touched object -play animation

    and then touched again its play other animation again how to do that :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)