Problem with amination frame

0 favourites
  • 14 posts
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • when using the code below, the trail button works when pressing T but not when clicking on the button. Why?

    frame 1

    frame 2

    Note: Animation is set to speed 0

  • Touch object has a property to use it like a mouse click too. Check it.

  • Because when you click an object your touch is also triggered so it repeats first command.

    Here is a CAPX demonstrating use of touch for different uses.

    https://www.dropbox.com/s/c1hxdpaell02t7s/Tap%20Example2.capx?dl=0

  • Oh OK. I get it. So I guess I should use mouse instead of touch for this to work.

  • Oh OK. I get it. So I guess I should use mouse instead of touch for this to work.

    You can use both but on click and on touch or tap will return the same result.

    You can have your user choose which they will use at the first of your game which is what I do. That way it can be played on a PC with mouse or tablet.

  • Well I think it must be coming from another problem because I still have the issue with a mouse event instead of a touch event.

    Thanks for the example, BTW!

  • If you still have the problem, try putting wait 0.1 sec action in t press and on touch trailbtn. both

  • In know how you made that 'or' event.

    You first made 2 separate events. 1 with the 'on key pressed'. And then 1 with the 'on touched'.

    Then you converted the event containing the 'on key pressed' to an 'or' block.

    Then you dragged the 'on touched' condition in that 'or' block.

    Then you deleted the empty event.

    Thing is, i dont know why it accepts this.

    If you try to directly add a second trigger (trigger conditions start with 'on') to an event that already contains a trigger ... then it will not accept that second trigger.

    Conclusion: i think that there should be no two triggers in 1 event. So,i am not surprised that is does not work.

    When a trigger is burred in conditions, it has to look up if it is allowed to run its actions.

    In this case, it looks up and bumps head on the 'on key' not being true.

    The other thing i see is the use of 'wait' to keep the next event from being true all the time that the current event is true. That is bad coding (my opinion).

    Also the 'triggers once while true' is a 'incomplete fix' for the problems created by the 'wait'.

    May i suggest to use a function. (i suppose that there is only 1 trailbutton)

    New root event

    On function (give it a name ... say "SWITCH")

    _______TrailOnOff = 0 ?

    ___________actions ___ set TrailOnOff to 1

    ______________________ do that visible/invisible stuff / plz dont use wait

    _______Else

    ___________actions ___ set TrailOnOff to 0

    ______________________ do that visible/invisible stuff / plz dont use wait

    New root event

    On key pressed

    ______ Call function "SWITCH"

    New root event

    On touched

    ______ Call function "SWITCH"

  • Awesome! It works perfectly that way. Thank you for your input. I am still trying to understand how C2 code works compare to JavaScript.

    Corrected code:

  • I still have a problem though the code is definitely better. Basically the button works only on one of the event (the rest works)

    The reason I need both is because some students will use only the keyboard and some students will use touch or mouse. I used mouse in the example but of course I could replace with touch which would also both mouse and tap.

    case 1:

    on start layout set trailOnOff = 1

    on trailONoff = 0/ set animation frame to 0

    else/ set animation frame to 1

    result: keyPress changes the button - mouse does not

    case 2:

    on start layout set trailOnOff = 1

    on trailONoff = 0/ set animation frame to 1

    else/ set animation frame to 0

    result: keyPress does not change the button - mouse does

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not sure if i understand that 'code'.

    Everything under 'on start layout' runs once, and on startup.

    So, if you want the animation frame to reflect the initial state of the global trailOnOff .. then just ..

    Global variable trailOnOff = 1 or 0 (whatever you choose)

    On start layout

    ______________set animationframe to trailOnOff

    Still assuming that there is only 1 trailbutton and 1 trail.

    If not, things got to be picked. You dont do that now.

    I dont see how the keypress will not work. Unless you have some 'thing' in the rest of the code.

  • I still have a problem though the code is definitely better. Basically the button works only on one of the event (the rest works)

    The reason I need both is because some students will use only the keyboard and some students will use touch or mouse. I used mouse in the example but of course I could replace with touch which would also both mouse and tap.

    case 1:

    on start layout set trailOnOff = 1

    on trailONoff = 0/ set animation frame to 0

    else/ set animation frame to 1

    result: keyPress changes the button - mouse does not

    case 2:

    on start layout set trailOnOff = 1

    on trailONoff = 0/ set animation frame to 1

    else/ set animation frame to 0

    result: keyPress does not change the button - mouse does

    I will take a look at it but my suggestion for education uses is to have the user select mouse or touch before starting play to eliminate that problem and you will have just one trigger variable to tell the events to use either mouse or touch.

    I do that in my games to avoid confusion and getting clicks and taps at the same time.

  • Can anyone help on this one.?

    Something strange happens :

    If I start with the mouse event, the button do not switch. However if I start with the T key (which is working) and then proceed to use the mouse it switches. So it seems that the trigger for the mouse event when chosen first is not firing properly.

    Note: the only reason I am doing both events is that specs for education covers all kind of special needs. Most students will use the mouse or tap events while some will use the keyboard.

  • OK. I feel very embarrassed. It actually works. The reason I thought it did not work is because I forgot to set the speed of the animation button to 0.

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