When i am rotating the image like 4 times it creates a shadow of 1 pixel of it in the top of the image that dissapear when im rotating it again and it appears back when im on the specific angle again. I rly have no idea why but the problem seems to be centerOO cuz if i comment the centerOO(); the problem is solved. Any ideas? Tetris.swf (87.9 KB) and the code is this:
package
{
import net.flashpunk.Entity;
import net.flashpunk.Graphic;
import net.flashpunk.graphics.Graphiclist;
import net.flashpunk.graphics.Image;
import net.flashpunk.Mask;
import net.flashpunk.utils.Input;
import net.flashpunk.utils.Key;
public class Piece extends Entity
{
[Embed(source = "../Assets/Entities/lines/line1.png")]protected const LINE1:Class;
[Embed(source = "../Assets/Entities/lines/line2.png")]protected const LINE2:Class;
[Embed(source = "../Assets/Entities/lines/line3.png")]protected const LINE3:Class;
[Embed(source = "../Assets/Entities/lines/line4.png")]protected const LINE4:Class;
private var img1:Image = new Image(LINE1);
private var img2:Image = new Image(LINE2);
private var img3:Image = new Image(LINE3);
private var img4:Image = new Image(LINE4);
private var theGraphic:Graphiclist = new Graphiclist();
private var imgCounter:int = 1;
public function Piece(x:Number, y:Number)
{
super(x, y);
graphic = theGraphic;
theGraphic.add(img1);
//theGraphic.add(img2);
//theGraphic.add(img3);
//theGraphic.add(img4);
img1.centerOO();
img2.centerOO();
img3.centerOO();
img4.centerOO();
img2.alpha = 0;
img3.alpha = 0;
img3.alpha = 0;
}
override public function update():void
{
follow();
rotateOnClick();
rotateUntillGood();
super.update();
}
private function follow():void
{
x = Input.mouseX;
y = Input.mouseY;
}
private function rotateOnClick():void
{
if (Input.mousePressed && img1.angle % 90 == 0) {
img1.angle-= 1;
if (imgCounter < 4) imgCounter++;
else imgCounter = 1;
}
}
private function rotateUntillGood():void
{
if (img1.angle % 90 != 0) {
if (90 - Math.abs(img1.angle) % 90 < 10) {
img1.angle -= 90 - Math.abs(img1.angle) % 90;
img2.angle = img3.angle = img4.angle = img1.angle;
return;
}
img1.angle-= 10;
img2.angle = img3.angle = img4.angle = img1.angle;
}
img2.angle = img3.angle = img4.angle = img1.angle;
}
}
}