Page 1 of 1
2 backgrounds 1 scrolling
Posted: Thu Dec 02, 2010 12:10 pm
by RensLensvelt
I'm trying to get 2 backgrounds, one on the top screen and one on the bottom.
The bottomscreen has to scroll.
When i use this code the bottom screen seems to 'crash' it shows half of the image, but then double...
Code: Select all
#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
#include "kaart.h"
#include "logo.h"
int main(void) {
int keys = 0;
int tx = 0;
touchPosition touch;
vramSetBankA(VRAM_A_MAIN_BG);
//vramSetBankB(VRAM_B_SUB_BG);
videoSetMode(MODE_5_2D);
videoSetModeSub(MODE_5_2D);
int TopScherm = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0);
bgSetPriority(TopScherm,3);
decompress(logoBitmap, BG_GFX, LZ77Vram);
int BtmScherm = bgInitSub(3, BgType_Bmp16, BgSize_B16_512x256, 0,0);
bgSetPriority(BtmScherm,3);
decompress(kaartBitmap, BG_GFX_SUB, LZ77Vram);
bgUpdate();
}
Re: 2 backgrounds 1 scrolling
Posted: Sat Dec 04, 2010 7:05 am
by zeromus
your game doesnt go into a loop. whatever it does, it only does once, and then the program exits. this is bogus.
Re: 2 backgrounds 1 scrolling
Posted: Wed Dec 08, 2010 10:49 am
by RensLensvelt
Sorry, didn't know you would need everything
this is the code so far
Code: Select all
#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
#include "kaart.h"
#include "logo.h"
#include "slider.h"
#include "dekantine.h"
#include "schuur2.h"
#include "schuur.h"
int main(void) {
int keys = 0;
//int sx = 0;
int sy = 0;
int tx = 0;
int geselecteerd = 0;
touchPosition touch;
vramSetBankA(VRAM_A_MAIN_BG);
//vramSetBankB(VRAM_B_SUB_BG);
videoSetMode(MODE_5_2D);
videoSetModeSub(MODE_5_2D);
int TopScherm = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0);
bgSetPriority(TopScherm,3);
decompress(logoBitmap, BG_GFX, LZ77Vram);
int BtmScherm = bgInitSub(3, BgType_Bmp16, BgSize_B16_512x256, 0,0);
bgSetPriority(BtmScherm,3);
decompress(kaartBitmap, BG_GFX_SUB, LZ77Vram);
bgUpdate();
while(!(keys & KEY_B))
{
scanKeys();
keys = keysHeld();
// if(keys & KEY_UP) sy--;
// if(keys & KEY_DOWN) sy++;
// if(keys & KEY_LEFT) sx--;
// if(keys & KEY_RIGHT) sx++;
if(geselecteerd == 1) {
if(keys & KEY_UP and sy > 0 ) sy--;
if(keys & KEY_DOWN and sy < 64 ) sy++;
};
//if(keys & KEY_LEFT) decompress(schuur2Bitmap, BG_GFX, LZ77Vram);
//if(keys & KEY_RIGHT) decompress(schuurBitmap, BG_GFX, LZ77Vram);
//if(keys & KEY_A) decompress(logoBitmap, BG_GFX, LZ77Vram);
touchRead(&touch);
swiWaitForVBlank();
if (touch.px > 1 and touch.py > 140) tx = touch.px;
if (touch.px > 20-tx and touch.px < 50-tx and touch.py >20 and touch.py < 50) {decompress(sliderBitmap, BG_GFX, LZ77Vram); geselecteerd = 1;};
if (touch.px > 80-tx and touch.px < 110-tx and touch.py >30 and touch.py < 60) {decompress(dekantineBitmap, BG_GFX, LZ77Vram); geselecteerd = 1;};
if (touch.px > 140-tx and touch.px < 170-tx and touch.py >40 and touch.py < 70) {decompress(schuur2Bitmap, BG_GFX, LZ77Vram); geselecteerd = 1;};
if (touch.px > 250-tx and touch.px < 280-tx and touch.py >50 and touch.py < 80) {decompress(schuurBitmap, BG_GFX, LZ77Vram); geselecteerd = 1;};
if (touch.px > 320-tx and touch.px < 350-tx and touch.py >60 and touch.py < 90) {decompress(logoBitmap, BG_GFX, LZ77Vram); geselecteerd = 1;};
bgSetScroll(BtmScherm, tx, 0);
bgSetScroll(TopScherm, 0, sy);
bgUpdate();
}
return 0;
}
Re: 2 backgrounds 1 scrolling
Posted: Wed Dec 08, 2010 7:27 pm
by zeromus
do you know what touch.px are and touch.py are when the stylus _isnt_ being pressed? maybe theyre values which confuse your program.
"seems to 'crash' it shows half of the image, but then double..." doesnt make much sense. if you upload the zip of your entire project then this could be 100% debugged.
Re: 2 backgrounds 1 scrolling
Posted: Thu Dec 09, 2010 8:47 am
by RensLensvelt
Here are 2 images.
The first is the map like i want to show it (png) I've put in some red blocks to make my problem more clear.
The second is a photo of the NDS running the program.