CenterOO and rotating a image problem


(billy2000) #1

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;
	}
}

}


(Martí Angelats i Ribera) #2

It may be something related about multiple angle changing and round. I’ll have a deeper look later on (it may be FP problem)


(billy2000) #3

Does anyone found anything? ty


(Darrin) #4

I looked it over and you are definitely right. It gets a shadow but I don’t know why. The only thing I can suggest is a work around. Why not just do a single image? Either premade and loaded from file or load the separate ones and build them into a single bmp before rotating.


(billy2000) #5

Interesting idea …the Problem is that i actually use 1 single image over there(the others are commented).


(Martí Angelats i Ribera) #6

Spritemap OP (the index is the number of rotations %4)


(billy2000) #7

and …can it be solved somehow? O: