23Fermer25
hine62Le 19/05/2018 à 02:47
I don't mean to highjack this thread, but I thought this code might be helpful. I've been messing round with palettes and sprites trying to figure out how they are set in memory for each sprite. When I needed multiple sprites of the same image or animation, only baseSprite is incremented. Each multiple sprite uses the same palette or palettes.

There might be a better way to do this, but this is what is working right now. I did notice that buildchar outputs the sprite and palette count, so you could input the counts manually.

//Load images currentBaseSprite = 16; //set sprite locations currentBasePalette = 16; //set pal location pictureInit(&layerOne, &Stars,currentBaseSprite,currentBasePalette,0,0,FLIP_NONE); palJobPut(currentBasePalette, Stars.palInfo->count,Stars.palInfo->data); //update basepalette and basesprite currentBaseSprite += Stars.tileWidth; currentBasePalette += Stars.palInfo->count; pictureInit(&testPlayer.pic, &playerShip, currentBaseSprite, currentBasePalette, testPlayer.x, testPlayer.y, FLIP_NONE); //copy pic to mem palJobPut(currentBasePalette, playerShip.palInfo->count, playerShip.palInfo->data); //copy pal to mem //populate player data testPlayer.x = 0; //player x y testPlayer.y = 224/2 + 16; testPlayer.width = 20; testPlayer.height = 20; testPlayer.spriteNum = currentBaseSprite; change_sprite_zoom(currentBaseSprite, 10, 10*16, 2); oldX = testPlayer.x; oldY = testPlayer.y; currentBaseSprite += playerShip.tileWidth; currentBasePalette += playerShip.palInfo->count; for(ii = 0; ii < ENEMY_MAX; ii++) { enemy[ii].x = routine.wayPoint[ii].x; enemy[ii].y = routine.wayPoint[ii].y; enemy[ii].width = (ORANGE_ENEMY5.tileWidth * 16) * (10/16); enemy[ii].height = (ORANGE_ENEMY5.tileHeight * 16) * (10/16); enemy[ii].xVel = -2; enemy[ii].yVel = 1; enemy[ii].alive = 1; enemy[ii].hits = routine.attack.power; enemy[ii].shotAlive = 0; enemy[ii].shotXorg = 0; enemy[ii].shotYorg = 15; enemy[ii].randShotTime = rand()%100; change_sprite_zoom(currentBaseSprite, 10, 10*16, 2); //enemy picture pictureInit(&enemy[ii].pic, &ORANGE_ENEMY5, currentBaseSprite, currentBasePalette, enemy[ii].x, enemy[ii].y, FLIP_NONE); //copy player palJobPut(currentBasePalette, ORANGE_ENEMY5.palInfo->count, ORANGE_ENEMY5.palInfo->data); //copy pal to mem //inc sprite data currentBaseSprite += ORANGE_ENEMY5.tileWidth;//increment sprite location //next enemy } currentBasePalette += ORANGE_ENEMY5.palInfo->count; //increment pal location //setup player shot pictures for(ii = 0; ii < PLAYER_MAX_SHOTS; ii++) { shot[ii].x = 400; shot[ii].y = 400; shot[ii].alive = 0; pictureInit(&shot[ii].pic, &playerShot, currentBaseSprite, currentBasePalette, shot[ii].x, shot[ii].y, FLIP_NONE); currentBaseSprite += playerShot.tileWidth; } palJobPut(currentBasePalette, playerShot.palInfo->count, playerShot.palInfo->data); currentBasePalette += playerShot_Palettes.count; //setup enemy shot pictures for(ii = 0; ii < PLAYER_MAX_SHOTS; ii++) { eshot[ii].x = 400; eshot[ii].y = 400; eshot[ii].alive = 0; eshot[ii].enemyNum = -1; pictureInit(&eshot[ii].pic, &enemyLaser, currentBaseSprite, currentBasePalette, eshot[ii].x, eshot[ii].y, FLIP_NONE); change_sprite_zoom(currentBaseSprite, 7, 7*16, 1); currentBaseSprite += enemyLaser.tileWidth; } palJobPut(currentBasePalette, enemyLaser.palInfo->count, enemyLaser.palInfo->data); currentBasePalette += enemyLaser.palInfo->count; //populate explosions for(ii = 0; ii < EXPLOSION_MAX; ii++) { explosionSpr[ii].x = 400; explosionSpr[ii].y = 0; explosionSpr[ii].xVel = 0.25; explosionSpr[ii].yVel = 0.5; //amount to fall explosionSpr[ii].alive = 0; explosionSpr[ii].remove = 0; explosionSpr[ii].currentBaseSprite = currentBaseSprite; explosionSpr[ii].currentBasePalette = currentBasePalette; aSpriteInit(&explosionSpr[ii].spr,&explosion,currentBaseSprite,currentBasePalette, explosionSpr[ii].x,explosionSpr[ii].y,0,FLIP_NONE,AS_FLAGS_DEFAULT); //explosionSpr[ii].spr.stepNum = 0; currentBaseSprite += explosion.maxWidth * explosion.frameCount; } palJobPut(currentBasePalette,explosion.palInfo->count, explosion.palInfo->data); currentBasePalette += explosion.palInfo->count;