optimize out some sprites and respect icon_offset
This commit is contained in:
@@ -34,15 +34,16 @@
|
||||
// First add the floor
|
||||
(let [tileSprite (data.floorSprite floor)]
|
||||
// TODO add cliffs if it's higher than the one in front of it
|
||||
(set tileSprite.x x)
|
||||
(set tileSprite.y (- y yOffset))
|
||||
(FlxMouseEventManager.add tileSprite
|
||||
// handle click on floor:
|
||||
->downTS {}
|
||||
->upTS {}
|
||||
->overTS (set overTS.color SELECTED_COLOR)
|
||||
->outTS (set outTS.color NORMAL_COLOR))
|
||||
(add tileSprite))
|
||||
(when tileSprite
|
||||
(set tileSprite.x x)
|
||||
(set tileSprite.y (- y yOffset))
|
||||
(FlxMouseEventManager.add tileSprite
|
||||
// handle click on floor:
|
||||
->downTS {}
|
||||
->upTS {}
|
||||
->overTS (set overTS.color SELECTED_COLOR)
|
||||
->outTS (set outTS.color NORMAL_COLOR))
|
||||
(add tileSprite)))
|
||||
|
||||
// TODO add any items
|
||||
|
||||
@@ -50,17 +51,16 @@
|
||||
|
||||
// TODO the wall sprites will be from different sheets defined by town/outdoor section
|
||||
(let [tileSprite (data.terrainSprite terrain)]
|
||||
(set tileSprite.x x)
|
||||
(set tileSprite.y (- y yOffset))
|
||||
(when (> tileSprite.height SPRITE_HEIGHT)
|
||||
(-= tileSprite.y SPRITE_HEIGHT))
|
||||
(FlxMouseEventManager.add tileSprite
|
||||
// Handle click on terrain:
|
||||
->downTS {}
|
||||
->upTS {}
|
||||
->overTS (set overTS.color SELECTED_COLOR)
|
||||
->outTS (set outTS.color NORMAL_COLOR))
|
||||
(add tileSprite)))
|
||||
(when tileSprite
|
||||
(+= tileSprite.x x)
|
||||
(+= tileSprite.y (- y yOffset))
|
||||
(FlxMouseEventManager.add tileSprite
|
||||
// Handle click on terrain:
|
||||
->downTS {}
|
||||
->upTS {}
|
||||
->overTS (set overTS.color SELECTED_COLOR)
|
||||
->outTS (set outTS.color NORMAL_COLOR))
|
||||
(add tileSprite))))
|
||||
(+= x (/ FLOOR_WIDTH 2))
|
||||
(+= y (/ FLOOR_HEIGHT 2))))
|
||||
(-= rowStartX (/ FLOOR_WIDTH 2))
|
||||
|
@@ -50,28 +50,18 @@ class ScenData {
|
||||
return spriteSheets[num];
|
||||
}
|
||||
|
||||
var es:FlxSprite = null;
|
||||
function emptySprite() {
|
||||
if (es == null) {
|
||||
es = new FlxSprite(0, 0);
|
||||
es.makeGraphic(46, 55, FlxColor.TRANSPARENT);
|
||||
es.alpha = 0;
|
||||
}
|
||||
return es;
|
||||
}
|
||||
|
||||
public function floorSprite(floorId:Int) {
|
||||
if (!(floorId >= 0 && floorId < 256))
|
||||
throw 'floor $floorId is out of range';
|
||||
if (!floorData.exists(floorId)) {
|
||||
return emptySprite();
|
||||
return null;
|
||||
}
|
||||
|
||||
var fd = floorData[floorId];
|
||||
|
||||
var sheet = floorOrTerrainSpriteSheet(fd.which_sheet);
|
||||
if (sheet == null) {
|
||||
return emptySprite();
|
||||
return null;
|
||||
}
|
||||
var sprite = new FlxSprite();
|
||||
sprite.loadGraphicFromSprite(sheet);
|
||||
@@ -86,31 +76,32 @@ class ScenData {
|
||||
if (!(terrainId >= 0 && terrainId < 512))
|
||||
throw 'terrain $terrainId is out of range';
|
||||
if (!terrainData.exists(terrainId)) {
|
||||
var s = new FlxSprite(0, 0);
|
||||
s.makeGraphic(46, 55, FlxColor.TRANSPARENT);
|
||||
return s;
|
||||
return null;
|
||||
}
|
||||
var td = terrainData[terrainId];
|
||||
|
||||
var sheet = floorOrTerrainSpriteSheet(td.which_sheet);
|
||||
if (sheet == null) {
|
||||
return emptySprite();
|
||||
return null;
|
||||
}
|
||||
var sprite = new FlxSprite();
|
||||
sprite.loadGraphicFromSprite(sheet);
|
||||
sprite.animation.frameIndex = td.which_icon;
|
||||
|
||||
sprite.x += td.icon_offset_x;
|
||||
sprite.y += td.icon_offset_y;
|
||||
|
||||
// TODO if it's a tall terrain combine it with the upper sprite and set its origin to offset y
|
||||
if (td.second_icon != -1) {
|
||||
var upperSprite = new FlxSprite();
|
||||
upperSprite.loadGraphicFromSprite(sheet);
|
||||
upperSprite.animation.frameIndex = td.second_icon;
|
||||
|
||||
var tallerSprite = new FlxSprite(0, 0);
|
||||
var tallerSprite = new FlxSprite(sprite.x, sprite.y);
|
||||
tallerSprite.makeGraphic(46, 110, FlxColor.TRANSPARENT, true);
|
||||
tallerSprite.stamp(upperSprite, 0, 0);
|
||||
tallerSprite.stamp(sprite, 0, 55);
|
||||
|
||||
tallerSprite.y -= 55;
|
||||
return tallerSprite;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user