Need help with a counter based on speed/linear motion of an actor
colander
Member Posts: 1,610
I have been trying to create an integer counter based on the speed an actor moves. As the actor increases speed the counter increases proportionately and as the actor slows down so does the count and when the actor stops so does the counter.
I can't figure out where to start with this one and I have tried searching but no joy so far. Does anyone have any suggestions?
I can't figure out where to start with this one and I have tried searching but no joy so far. Does anyone have any suggestions?
Comments
Use a function such as 10÷velocity for the number of seconds that it takes the counter to update. This is called an inverse proportion. If velocity is 10, the counter updates every 1 second (10÷10=1). If velocity is 20, the counter updates every 0.5 seconds (10÷20=0.5). If the velocity is 200, the counter updates every 0.05 seconds (10÷200=0.05), etc. We'll call this update value game.counterDuration (real) and constrain it to 10÷self.[velocity].
You'll need to make a custom timer instead of using the Timer behavior because the Timer behavior cannot change the duration of its cycle once the app is running (even though you're technically allowed to put an attribute in a Timer expression). Create a timestamp by changing game.timeStamp (real) to game.Time as in this rule:
When game.Time ≥ game.timeStamp+game.counterDuration
Change attribute game.counter to game.counter+1
Change attribute game.timeStamp to game.Time
You'll have to check for self.[velocity] = 0 because then game.counterDuration would be 10÷0 and you'll want to avoid that.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I am trying to set up a combination of scrolling methods to display table data. The table could be as large as 30,000 rows x 17 Columns. I will need to display up to a 1,000 rows at a time. The app will spawn a grid of cells 52 rows x 17 columns. This grid will be used to display up to 1000 rows x 17 columns of the table.
I am using a combination of scrolling methods as shown in the attached project. I have just scattered some cells around so you can see the floating scroll method working. The camera will move over a table (Floating effect) and when it hits the the top or bottom the counter will increase or decrease. I will then use the counter (0 to whatever, no negative numbers) to offset the row index of the table cells to change the display text in them. This will scroll but won't be as pretty as the floating method.
Anyway I won't boar you anymore with why I am trying to do it this way. It works but not well. When I scroll the number does not increase or decrease smoothly. I think this is because linear velocity is constrained by the floating scroll method in the instance of the Drag actor.
To see this open the attached project click Preview then click the screen and the blue Drag actor will appear. Swipe up when the floating scene reaches it limit at the bottom the counter in the Drag actor will start to increase. If you swipe slowly the counter increase smoothly but when you try to go fast it slows down or freezes.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template