Skip to main content
15 events
when toggle format what by license comment
Jul 8, 2014 at 14:36 vote accept Jeff Hanson
Jul 8, 2014 at 14:36 comment added Jeff Hanson Thanks Wolfgang, I think the code does what it's supposed to do now. I counted the prints for black and white and while it shows 1 hertz less for the first second but the rest seems to be fine.(it goes back to the correct hertz on the rest of time.) I only tried up to 3-4 seconds and for 3, 7 and 9 but I'm guessing it's the same for the rest. I'll accept your solution. I can't measure the flickering until after a week but I think it will work, otherwise I will be back. Thanks very much for helping me out and bearing with my ignorance. Now I just hope this solution works perfectly! :)
Jul 6, 2014 at 23:14 history edited Wolfgang Skyler CC BY-SA 3.0
added 33 characters in body
Jul 6, 2014 at 23:13 comment added Wolfgang Skyler Sorry, I had my formula wrong. Adjusted now.
Jul 6, 2014 at 23:00 comment added Wolfgang Skyler And the thing at the end is a little bit of safety. If we just keep adding more and more to dtime, then it eventually reaches infinity. However, If dtime == 0, then the whole terms within the sine formula becomes zero. Sin(0) == 0, so wave will be 0. so if wave == 0, then I know that I can set dtime to 0 without having sudden shifts in wave.
Jul 6, 2014 at 22:59 comment added Wolfgang Skyler Sorry. Does it work as you wanted at least? Starting with Mathf.sin, that provides the oscillation. The formula within is A bit more complicated. I honestly don't entirely know myself. I could probably work though it, but I just found a few sources online that used that and went with it.
Jul 6, 2014 at 21:56 comment added Jeff Hanson I tried running it where I exchanged the variable cycleHz with 9 and printed out deltatime, dtime and wave. I got the values 0.0164 to 0.0166 for deltatime but for dtime and wave I got 0. Could I please ask you to explain the code to me like was I an idiot? (Yep, feeling like one right now)
Jul 6, 2014 at 21:55 comment added Jeff Hanson I'm sorry. I've tried to look at the code for a few hours now (even when to get something to each to get a break from it) but I don't understand it. I can see that you add deltatime to dtime to let dtime get bigger. (printing out deltatime only I can see that it starts on 0.2 and then fast go down to 0.0164-0.0166). I don't understand the wave formula except that we are dividing with cycleHz (which would be 9 in my case) to check where we are on the wave. If we are over 0.0f then it's time to turn black if not then it's white.(on/off) I didn't get why you had to reset dtime at the end either.
Jul 6, 2014 at 19:17 history edited Wolfgang Skyler CC BY-SA 3.0
Added in an explination of Hz and how to implement it into code.
Jul 6, 2014 at 18:15 comment added Wolfgang Skyler The comments section doesn't accept newlines, but it kept the spaces for the indent, that's what happened there. Give me a few minutes, I need to work out the code an explanation as to why the code works, and why that code. You should look into how to prevent a mass of elements from lowering your frame-rate.
Jul 6, 2014 at 17:07 comment added Jeff Hanson errr...dunno what happened above. Anyway that code is no go. One frequency and very simple code. Aye the game slows down.
Jul 6, 2014 at 17:04 comment added Jeff Hanson using UnityEngine; using System.Collections; public class flicker : MonoBehaviour { public Sprite white; public Sprite black; public SpriteRenderer ren; // Update is called once per frame void FixedUpdate () { if (ren.sprite == white) { ren.sprite = black; } else { ren.sprite = white; } } }
Jul 6, 2014 at 16:43 comment added Wolfgang Skyler So the flickering code, as you have it, works fine. It's just that the game slows down when you are drawing to many elements to the screen?
Jul 6, 2014 at 14:29 comment added Jeff Hanson I tried FixedUpdate it didn't work out either. I tried a print out which showed it was impossible. The 9Hz is not for the whole game but for the flickering square. The lagging came from the gameobjects in the game. The main player is trying to catch elements dropping from the sky and if there are a bit too many the game starts to go slow for a few secs or more which means the flickering does too. This is the reason why I'm seeking another way which works (like the Timer class from c#...) and hopefully it would work.
Jul 6, 2014 at 14:05 history answered Wolfgang Skyler CC BY-SA 3.0