Resolution adapting backgrounds and 3 additional layers

Version:

1.0

Added on:

21 Dec 2015 16:14

Tags:

Description:
A very messed up snippet teaching you how to adapt official backgrounds to your current screen resolution and get a total of 7 background layers instead of the usual 4
  1. // Prepare a 10x32 layer 8. Have each layer image exactly 10x8. Start from layer 8 on top, end with layer 5 on bottom.
  2.  
  3. void onDrawLayer8(jjPLAYER@ p, jjCANVAS@ screen) // Let's subdivide the contents from layer 8 into 4 different layers, shall we?
  4.   {
  5.   jjPIXELMAP doLayer11(0, 0, 320, 240, 8); // Have the layer 8 image on tiles from 1,1 to 10,8 (or 10,7 if it's a 320x200 image)
  6.   jjANIMFRAME@ layer11 = jjAnimFrames[jjAnimations[jjAnimSets[ANIM::BOLLPLAT].firstAnim].firstFrame]; // Assuming you're not using boll platforms, place one somewhere nearby the start, but not in a visible place.
  7.   layer11.hotSpotX = 0;
  8.   layer11.hotSpotY = 0; // So the background image is perfectly aligned.
  9.   doLayer11.save(layer11);
  10.   screen.drawResizedSprite(0, 0, ANIM::BOLLPLAT, 0, 0, 0.003125 * jjResolutionWidth, 0.0041666667 * jjResolutionHeight, SPRITE::NORMAL, 0); // Or 0.005 if it's a 320x200 image, but it will appear stretched in 4:3 resolutions.
  11.   jjPIXELMAP doLayer10(0, 8 * 32, 10 * 32, 8 * 32, 8); // Have the layer 7 image on tiles from 1,9 to 10,16
  12.   jjANIMFRAME@ layer10 = jjAnimFrames[jjAnimations[jjAnimSets[ANIM::FRUITPLAT].firstAnim].firstFrame]; // We'll need more frames, so assuming you'll not use the first 4 platforms, let's replace their sprites with backgrounds.
  13.   layer10.hotSpotX = 0;
  14.   layer10.hotSpotY = 0;
  15.   doLayer10.save(layer10);
  16.   screen.drawResizedSprite(0 - (p.cameraX % ((0.25 * jjResolutionWidth) * 32) / 8), 0 - (p.cameraY % (160 * 32) / 32), ANIM::FRUITPLAT, 0, 0, 0.003125 * jjResolutionWidth, 0.0041666667 * jjResolutionHeight, SPRITE::NORMAL, 0); // Higher divisions mean further background.
  17.   screen.drawResizedSprite(jjResolutionWidth - (p.cameraX % ((0.25 * jjResolutionWidth) * 32) / 8), 0 - (p.cameraY % (160 * 32) / 32), ANIM::FRUITPLAT, 0, 0, 0.003125 * jjResolutionWidth, 0.0041666667 * jjResolutionHeight, SPRITE::NORMAL, 0); // Leaving the Y origin to 0 is good for backgrounds with a ceiling.
  18.   jjPIXELMAP doLayer9(0, 16 * 32, 10 * 32, 8 * 32, 8); // Shortly, place the next layer's tiles each 8 tiles down, or customize the area if you want.
  19.   jjANIMFRAME@ layer9 = jjAnimFrames[jjAnimations[jjAnimSets[ANIM::GRASSPLAT].firstAnim].firstFrame];
  20.   layer9.hotSpotX = 0;
  21.   layer9.hotSpotY = 0;
  22.   doLayer9.save(layer9);
  23.   screen.drawResizedSprite(0 - (p.cameraX % ((0.125 * jjResolutionWidth) * 32) / 4), 0 - (p.cameraY % (80 * 32) / 16), ANIM::GRASSPLAT, 0, 0, 0.003125 * jjResolutionWidth, 0.0041666667 * jjResolutionHeight, SPRITE::NORMAL, 0);
  24.   screen.drawResizedSprite(jjResolutionWidth - (p.cameraX % ((0.125 * jjResolutionWidth) * 32) / 4), 0 - (p.cameraY % (80 * 32) / 16), ANIM::GRASSPLAT, 0, 0, 0.003125 * jjResolutionWidth, 0.0041666667 * jjResolutionHeight, SPRITE::NORMAL, 0); // Increase the Y origin according to the level height.
  25.   jjPIXELMAP doLayer8(0, 24 * 32, 10 * 32, 8 * 32, 8); // Once you're done with these, put whatever you want on layers 5-7 and enjoy watching!
  26.   jjANIMFRAME@ layer8 = jjAnimFrames[jjAnimations[jjAnimSets[ANIM::PINKPLAT].firstAnim].firstFrame];
  27.   layer8.hotSpotX = 0;
  28.   layer8.hotSpotY = 0;
  29.   doLayer8.save(layer8);
  30.   screen.drawResizedSprite(0 - (p.cameraX % ((0.0625 * jjResolutionWidth) * 32) / 2), 0 - (p.cameraY / 8), ANIM::PINKPLAT, 0, 0, 0.003125 * jjResolutionWidth, 0.0041666667 * jjResolutionHeight, SPRITE::NORMAL, 0); // The Y positions (speeds) are examples. For now, you may want to set them to 0.
  31.   screen.drawResizedSprite(jjResolutionWidth - (p.cameraX % ((0.0625 * jjResolutionWidth) * 32) / 2), 0 - (p.cameraY / 8), ANIM::PINKPLAT, 0, 0, 0.003125 * jjResolutionWidth, 0.0041666667 * jjResolutionHeight, SPRITE::NORMAL, 0);
  32.   }