私はiPhoneでチェスゲームを開発しようとしていますが、それ以外の重要な細部にこだわってしまってしまいました。誰かが欠けている作品を見ることができますか?コアグラフィックスが黒く塗りつぶす
ここに問題があります。ユーザーが四角形をクリックすると、色が薄くなります。実際に何が起こっているのですか、それは私がそれを設定した色に関係なく、黒を描くだけです。
ここに私が得るもののイメージがあります。黒丸は赤色または任意の色でなければなりません。
ここでは、私が描いているUIViewが部分的に表示されていることに注意してください。疑問に思うのですが、私は完璧になりたいです。
最後に、層のためのコード:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
rowSelected = 0;
colSelected = 0;
}
return self;
}
-(void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
CGContextSetRGBStrokeColor(context, 255.0, 0.0, 0.0, 1.0);
if (rowSelected && colSelected)
{
int gridsize = (self.frame.size.width/8);
int sx = (colSelected-1) * gridsize;
int sy = (rowSelected-1) * gridsize;
int ex = gridsize;
int ey = gridsize;
CGContextFillEllipseInRect(context, CGRectMake(sx,sy,ex,ey));
}
}
// Handles the start of a touch
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
int gridsize = (self.frame.size.width/8);
// Position of touch in view
UITouch *touch = [[event allTouches] anyObject];
CGPoint loc = [touch locationInView:self.superview];
int x = loc.x/gridsize;
int y = loc.y/gridsize;
rowSelected = y + 1;
colSelected = x + 1;
[self setNeedsDisplay];
}
私はなど、アルファと一緒に遊んで、1ではなく255の値を使用して、多くのことを試してみましたが、私はしています固体黒以外の何かを得ることはできません。
EDIT:
また、ここでは、このビューのスーパーのコードです:
@implementationのチェス盤
-(id)initWithFrame:(CGRect)frame
{
if (self != [super initWithFrame:frame])
return self;
int SQUARE_SIZE = frame.size.width/8;
currentSet = BW;
UIImage *img = [UIImage imageNamed:@"board.png"];
background = [[UIImageView alloc] initWithImage:img];
[background setFrame:frame];
[self addSubview:background];
overlay = [[ChessBoardOverlay alloc] initWithFrame:frame];
[self addSubview:overlay];
'CGContextSetRGBFillColor'を使ってみましたか? –
いいえ、それだけです。ああ、私はそれがそれのようなものであることを知っていた。 – jakev
色の値の範囲は「0.0」〜「1.0」で、「0.0」〜「255.0」ではありません。 – JustSid