Commit 1f3dd517 authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

prepare using multiple sprites per segment

parent 9ef03c8e
......@@ -34,7 +34,7 @@ Snake.prototype.Destroy = function()
while (this._segments.length>0)
{
let segment = this._segments.pop();
this._segmentContainer.removeChild(segment.GetSprite());
segment.RemoveSprites();
this._segmentPool.free(segment);
}
......@@ -76,7 +76,7 @@ Snake.prototype.SetLength = function(newLength)
while (this.GetLength() > newLength)
{
let seg = this._segments.pop();
this._segmentContainer.removeChild(seg.GetSprite());
seg.RemoveSprites();
this._segmentPool.free(seg);
}
......@@ -89,8 +89,7 @@ Snake.prototype.SetLength = function(newLength)
}
segment.SetTint(this._colorScheme[i % this._colorScheme.length]);
segment.SetScale(this.spriteScale);
this._segmentContainer.addChildAt(segment.GetSprite(), 0);
segment.AddSpritesFront(this._segmentContainer);
this._segments.push(segment);
}
};
......
......@@ -9,9 +9,20 @@ function SnakeSegment(texture)
this._sprite.alpha = 0.8;
}
SnakeSegment.prototype.GetSprite = function()
SnakeSegment.prototype.AddSpritesFront = function(container)
{
return this._sprite;
container.addChildAt(this._sprite, 0);
};
SnakeSegment.prototype.RemoveSprites = function()
{
this._sprite.parent.removeChild(this._sprite);
};
SnakeSegment.prototype.UpdateSprites = function()
{
this._sprite.x = this.x;
this._sprite.y = this.y;
};
SnakeSegment.prototype.SetTint = function(tint)
......@@ -43,9 +54,3 @@ SnakeSegment.prototype.MoveDirection = function(direction, length)
this.y + length*Math.sin(direction)
);
};
SnakeSegment.prototype.UpdateSprites = function()
{
this._sprite.x = this.x;
this._sprite.y = this.y;
};
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment