This site requires JavaScript, please enable it in your browser!
Greenfoot back
SOUPNAZI
SOUPNAZI wrote ...

2015/5/10

Piggybacking another users question for help...clarification

SOUPNAZI SOUPNAZI

2015/5/10

#
Good evening fellow programmers, I desparately require your assistance if you please. I was having great difficulty with transparency of an object but "danpost" kindly assisted me with that...but I am still confused however about making an object blink continuously. Why is this same code not allowing my to change the -5 to a 0 OR 255 to allow the turtle to blink continuously for me? I keep getting errors. I read that it cant go below zero & has to be 0-255 yet negative 5 overrides this rule. I was assuming by alternating 0 & 255 that it would make the turtle be at full capacity then blink if you will to invisible & back to full & repeat that cycle but my executions are not working. Another user stated their method for transparency was this: public void act() { if(canSee(Crab.class)) { i=getImage(); t=i.getTransparency()-5; if(t<0) { t=0; } i.setTransparency(t); setImage(i); } } this is the question/code I piggybacked off of from here PLEASE CLICK Again, I am new to this so please forgive my ignorance. Thank you in advance for any assistance you may provide. Good day
danpost danpost

2015/5/10

#
The '-5' is not overriding the rule. It is an adjustment to the current transparency value:
int t = i.getTransparency()-5;
At this point, 't' is just an integer value, not a transparency value.
if (t < 0)
This line checks to see if that value is less then zero. The value is set to zero if found below zero before actually setting the transparency of the image. To make an object blink, you need a timer. I think Super_Hippo just replied to someone about this. Check out some of the other most recent discussion threads.
You need to login to post a reply.