pictcode / app / webroot / js / pictcode / sprite_data.js @ 0b1b8047
履歴 | 表示 | アノテート | ダウンロード (7.881 KB)
| 1 |
define(["utility"], function(utility){ |
|---|---|
| 2 |
|
| 3 |
//----------------Sprite画像----------------//
|
| 4 |
|
| 5 |
var spriteImageInfos = [
|
| 6 |
|
| 7 |
//Vehicle
|
| 8 |
{imageNames:["001_char_img_car_010.png", "001_char_img_car_020.png"], category:"car", imageKey:0},
|
| 9 |
{imageNames:["001_char_img_car_030.png", "001_char_img_car_040.png"], category:"car", imageKey:1},
|
| 10 |
{imageNames:["001_char_img_car_050.png", "001_char_img_car_060.png"], category:"car", imageKey:2},
|
| 11 |
{imageNames:["001_char_img_car_070.png", "001_char_img_car_080.png"], category:"car", imageKey:3},
|
| 12 |
{imageNames:["001_char_img_bus_010.png", "001_char_img_bus_020.png"], category:"car", imageKey:4},
|
| 13 |
{imageNames:["001_char_img_bus_030.png", "001_char_img_bus_040.png"], category:"car", imageKey:5},
|
| 14 |
{imageNames:["car03.png"], category:"vehicle", imageKey:1},
|
| 15 |
|
| 16 |
//Animal
|
| 17 |
{imageNames:["001_char_img_dolphin_010.png", "001_char_img_dolphin_020.png"], category:"animal", imageKey:100},
|
| 18 |
{imageNames:["001_char_img_whale_010.png", "001_char_img_whale_020.png"], category:"animal", imageKey:101},
|
| 19 |
{imageNames:["001_char_img_dog_010.png"], category:"animal", imageKey:102},
|
| 20 |
{imageNames:["001_char_img_dog_020.png", "001_char_img_dog_030.png"], category:"animal", imageKey:103},
|
| 21 |
{imageNames:["001_char_img_dog_040.png"], category:"animal", imageKey:104},
|
| 22 |
{imageNames:["001_char_img_dog_050.png", "001_char_img_dog_060.png"], category:"animal", imageKey:105},
|
| 23 |
{imageNames:["001_char_img_cat_010.png"], category:"animal", imageKey:106},
|
| 24 |
{imageNames:["001_char_img_cat_020.png", "001_char_img_cat_030.png"], category:"animal", imageKey:107},
|
| 25 |
{imageNames:["001_char_img_mouse_010.png"], category:"animal", imageKey:108},
|
| 26 |
{imageNames:["001_char_img_mouse_020.png", "001_char_img_mouse_030.png"], category:"animal", imageKey:109},
|
| 27 |
{imageNames:["001_char_img_mole_010.png"], category:"animal", imageKey:110},
|
| 28 |
{imageNames:["001_char_img_mole_020.png"], category:"animal", imageKey:111},
|
| 29 |
{imageNames:["001_char_img_mole_030.png"], category:"animal", imageKey:112},
|
| 30 |
|
| 31 |
//Background
|
| 32 |
{imageNames:["001_char_bg_bg_010.png"], category:"background", imageKey:200},
|
| 33 |
{imageNames:["001_char_bg_bg_020.png"], category:"background", imageKey:201},
|
| 34 |
{imageNames:["001_char_bg_bg_030.png"], category:"background", imageKey:202},
|
| 35 |
{imageNames:["001_char_bg_bg_040.png"], category:"background", imageKey:203},
|
| 36 |
|
| 37 |
//Artifact
|
| 38 |
{imageNames:["001_char_img_pipe_010.png"], category:"artifact", imageKey:300},
|
| 39 |
|
| 40 |
//Airplane
|
| 41 |
{imageNames:["001_char_img_airplane_010.png"], category:"airplane", imageKey:400},
|
| 42 |
{imageNames:["001_char_img_airplane_020.png"], category:"airplane", imageKey:401},
|
| 43 |
{imageNames:["001_char_img_airplane_030.png"], category:"airplane", imageKey:402},
|
| 44 |
{imageNames:["001_char_img_airplane_040.png"], category:"airplane", imageKey:403},
|
| 45 |
{imageNames:["001_char_img_bomb_010.png", "001_char_img_bomb_020.png"], category:"airplane", imageKey:404},
|
| 46 |
{imageNames:["001_char_img_bomb_030.png", "001_char_img_bomb_040.png"], category:"airplane", imageKey:405},
|
| 47 |
|
| 48 |
//Board
|
| 49 |
{imageNames:["001_char_img_display_010.png"], category:"board", imageKey:500},
|
| 50 |
{imageNames:["001_char_img_display_020.png"], category:"board", imageKey:501},
|
| 51 |
{imageNames:["001_char_img_display_030.png"], category:"board", imageKey:502},
|
| 52 |
{imageNames:["game_clear.png"], category:"board", imageKey:503},
|
| 53 |
{imageNames:["game_over.png"], category:"board", imageKey:504},
|
| 54 |
{imageNames:["arrow1.png"], category:"board", imageKey:505},
|
| 55 |
{imageNames:["transparent_board.png"], category:"board", imageKey:506},
|
| 56 |
|
| 57 |
//Fish
|
| 58 |
{imageNames:["001_char_img_fish_010.png", "001_char_img_fish_020.png"], category:"fish", imageKey:600},
|
| 59 |
{imageNames:["001_char_img_fish_030.png", "001_char_img_fish_040.png"], category:"fish", imageKey:601},
|
| 60 |
{imageNames:["001_char_img_fish_050.png", "001_char_img_fish_060.png"], category:"fish", imageKey:602},
|
| 61 |
{imageNames:["shell.png"], category:"fish", imageKey:603},
|
| 62 |
|
| 63 |
//Instrument
|
| 64 |
{imageNames:["001_char_img_inst_010.png", "001_char_img_inst_020.png"], category:"instrument", imageKey:700},
|
| 65 |
{imageNames:["001_char_img_inst_030.png", "001_char_img_inst_040.png"], category:"instrument", imageKey:701},
|
| 66 |
{imageNames:["001_char_img_inst_050.png", "001_char_img_inst_060.png"], category:"instrument", imageKey:702},
|
| 67 |
{imageNames:["music_note.png"], category:"instrument", imageKey:703},
|
| 68 |
]; |
| 69 |
|
| 70 |
function loadSpriteImages(sprts, didLoadImages){ |
| 71 |
var loadingCount = 0; |
| 72 |
var isLoading = false; |
| 73 |
for (var i = 0; i < sprts.length; i++) { |
| 74 |
|
| 75 |
var sprite = sprts[i];
|
| 76 |
var spriteImageInfo = _.find(spriteImageInfos, function(spImgInf){ |
| 77 |
return sprite.imageKey == spImgInf.imageKey;
|
| 78 |
}); |
| 79 |
|
| 80 |
// if (!spriteImageInfo || spriteImageInfo.images) {
|
| 81 |
// continue;
|
| 82 |
// };
|
| 83 |
isLoading = true;
|
| 84 |
|
| 85 |
spriteImageInfo.images = []; |
| 86 |
sprite.images = spriteImageInfo.images; |
| 87 |
loadingCount += spriteImageInfo.imageNames.length; |
| 88 |
// var lc = 0;
|
| 89 |
_.each(spriteImageInfo.imageNames, function(imageName){
|
| 90 |
//var path = "image/sprite/" + spriteImageInfo.category + "/" + imageName;
|
| 91 |
var path = "/img/pictcode/sprite/" + spriteImageInfo.category + "/" + imageName; |
| 92 |
var spImage = new Image(); |
| 93 |
spImage.src = path; |
| 94 |
spriteImageInfo.images.push(spImage); |
| 95 |
spImage.onload = function(){ |
| 96 |
// lc++;
|
| 97 |
// if (lc >= spriteImageInfo.imageNames.length) {
|
| 98 |
// loadingCount--;
|
| 99 |
// };
|
| 100 |
loadingCount--; |
| 101 |
if (loadingCount <= 0) { |
| 102 |
didLoadImages(); |
| 103 |
}; |
| 104 |
} |
| 105 |
}); |
| 106 |
}; |
| 107 |
if (!isLoading) {
|
| 108 |
didLoadImages(); |
| 109 |
}; |
| 110 |
} |
| 111 |
|
| 112 |
function getCategorizedSpriteImageInfos(category, initSize){ |
| 113 |
var categorizedImageInfos = [];
|
| 114 |
_.each(spriteImageInfos, function(spriteImageInfo){
|
| 115 |
if (spriteImageInfo.category == category) {
|
| 116 |
categorizedImageInfos.push(spriteImageInfo); |
| 117 |
if (!spriteImageInfo.images) {
|
| 118 |
spriteImageInfo.images = []; |
| 119 |
_.each(spriteImageInfo.imageNames, function(imageName){
|
| 120 |
//var path = "image/sprite/" + spriteImageInfo.category + "/" + imageName;
|
| 121 |
var path = "/img/pictcode/sprite/" + spriteImageInfo.category + "/" + imageName; |
| 122 |
var spImage = new Image(); |
| 123 |
spImage.src = path; |
| 124 |
spImage.width = initSize/2;
|
| 125 |
spImage.height = initSize/2;
|
| 126 |
spriteImageInfo.images.push(spImage); |
| 127 |
}); |
| 128 |
spriteImageInfo.images[0].onload = function(){ |
| 129 |
setSpriteImageSize(spriteImageInfo.images[0], initSize);
|
| 130 |
} |
| 131 |
}else{
|
| 132 |
var spImage = spriteImageInfo.images[0]; |
| 133 |
setSpriteImageSize(spriteImageInfo.images[0], initSize);
|
| 134 |
}; |
| 135 |
}; |
| 136 |
}); |
| 137 |
return categorizedImageInfos;
|
| 138 |
} |
| 139 |
|
| 140 |
function setSpriteImageSize(spImage, size){ |
| 141 |
var naturalSize = utility.getImageNaturalSize(spImage);
|
| 142 |
var width = size * naturalSize.width / (naturalSize.width+naturalSize.height);
|
| 143 |
var height = size * naturalSize.height / (naturalSize.width+naturalSize.height);
|
| 144 |
spImage.width = width; |
| 145 |
spImage.height = height; |
| 146 |
} |
| 147 |
|
| 148 |
function findSpriteImageInfoFromImageKey(imageKey){ |
| 149 |
var spriteImageInfo = _.find(spriteImageInfos, function(spImgInf){ |
| 150 |
return spImgInf.imageKey == imageKey;
|
| 151 |
}); |
| 152 |
return spriteImageInfo;
|
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
//----------------カテゴリ画像----------------//
|
| 157 |
|
| 158 |
var categoryInfos =[
|
| 159 |
{name: "car", imageKey: "ctgry_spr_004"},
|
| 160 |
{name: "airplane", imageKey: "ctgry_spr_006"},
|
| 161 |
{name: "animal", imageKey: "ctgry_spr_001"},
|
| 162 |
{name: "fish", imageKey: "ctgry_spr_008"},
|
| 163 |
{name: "background", imageKey: "ctgry_spr_003"},
|
| 164 |
{name: "instrument", imageKey: "ctgry_spr_007"},
|
| 165 |
{name: "artifact", imageKey: "ctgry_spr_002"},
|
| 166 |
{name: "board", imageKey: "ctgry_spr_005"},
|
| 167 |
]; |
| 168 |
|
| 169 |
return {
|
| 170 |
spriteImageInfos:spriteImageInfos,
|
| 171 |
loadSpriteImages:loadSpriteImages,
|
| 172 |
getCategorizedSpriteImageInfos:getCategorizedSpriteImageInfos,
|
| 173 |
findSpriteImageInfoFromImageKey:findSpriteImageInfoFromImageKey,
|
| 174 |
categoryInfos:categoryInfos,
|
| 175 |
}; |
| 176 |
}); |