Problem with amination frame

Get help using Construct 2

Post » Tue Feb 21, 2017 3:11 pm

when using the code below, the trail button works when pressing T but not when clicking on the button. Why?
Image
Image frame 1
Image frame 2

Note: Animation is set to speed 0
B
8
S
1
Posts: 86
Reputation: 618

Post » Tue Feb 21, 2017 3:26 pm

Touch object has a property to use it like a mouse click too. Check it.
Lead developer at Octeto Studios
Visit our portfolio at: http://www.octetostudios.com/ :)
Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,613

Post » Tue Feb 21, 2017 3:33 pm

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
Banned User
B
28
S
7
G
58
Posts: 1,229
Reputation: 34,830

Post » Tue Feb 21, 2017 5:55 pm

Oh OK. I get it. So I guess I should use mouse instead of touch for this to work.
B
8
S
1
Posts: 86
Reputation: 618

Post » Tue Feb 21, 2017 6:02 pm

resdesign wrote: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.
Banned User
B
28
S
7
G
58
Posts: 1,229
Reputation: 34,830

Post » Tue Feb 21, 2017 6:09 pm

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!
B
8
S
1
Posts: 86
Reputation: 618

Post » Wed Feb 22, 2017 6:01 am

If you still have the problem, try putting wait 0.1 sec action in t press and on touch trailbtn. both :D
B
79
S
31
G
7
Posts: 148
Reputation: 9,179

Post » Wed Feb 22, 2017 12:17 pm

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"
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Feb 22, 2017 4:17 pm

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:
Image
B
8
S
1
Posts: 86
Reputation: 618

Post » Wed Feb 22, 2017 4:28 pm

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
B
8
S
1
Posts: 86
Reputation: 618

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests