Gamebuino Library Issues

Advice on general approaches or feasibility and discussions about game design

Re: Gamebuino Library Issues

Postby TheSpikeFactory » Sat Feb 14, 2015 3:17 am

I seem to be having a different problem, but it still prevents me from verifying the code
Last edited by TheSpikeFactory on Sat Feb 14, 2015 3:27 am, edited 1 time in total.
TheSpikeFactory
 
Posts: 23
Joined: Wed Feb 11, 2015 11:42 pm

Re: Gamebuino Library Issues

Postby TheSpikeFactory » Sat Feb 14, 2015 3:19 am

Well, it sadly does not work for me.
Last edited by TheSpikeFactory on Sat Feb 14, 2015 3:26 am, edited 1 time in total.
TheSpikeFactory
 
Posts: 23
Joined: Wed Feb 11, 2015 11:42 pm

Re: Gamebuino Library Issues

Postby TheSpikeFactory » Sat Feb 14, 2015 3:23 am

#include <SPI.h> //imports the SPI library
#include <Gamebuino.h> //imports the Gamebuino library
Gamebuino gb; //creates a Gamebuino object named gb

static unsigned char PROGMEM sprite[] =
{
12,6,
B000111100000,
B010101001000,
B010000001000,
B001111110000,
B000100000000,
B000001000000,
};

void setup(){
gb.begin());
//display the main menu
gb.titleScreen(F("Dart Monkey Sprite"));
}
gb.sound.playTick();
//the main loop
void loop(){
while(true) {
if(gb.update()){
gb.display.drawBitmap(12,6,sprite);
}
}
}
Using this exact code, this is the error: sketch_feb13b.ino:5:37: error: variable 'sprite' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
sketch_feb13b.ino:8:3: error: 'B000111100000' was not declared in this scope
sketch_feb13b.ino:9:3: error: 'B010101001000' was not declared in this scope
sketch_feb13b.ino:10:3: error: 'B010000001000' was not declared in this scope
sketch_feb13b.ino:11:3: error: 'B001111110000' was not declared in this scope
sketch_feb13b.ino:12:3: error: 'B000100000000' was not declared in this scope
sketch_feb13b.ino:13:3: error: 'B000001000000' was not declared in this scope
sketch_feb13b.ino: In function 'void setup()':
sketch_feb13b.ino:17:13: error: expected ';' before ')' token
sketch_feb13b.ino: At global scope:
sketch_feb13b.ino:21:1: error: 'gb' does not name a type
Error compiling.
TheSpikeFactory
 
Posts: 23
Joined: Wed Feb 11, 2015 11:42 pm

Re: Gamebuino Library Issues

Postby Skyrunner65 » Sat Feb 14, 2015 3:29 am

Be sure to quote what I have said, and learn how to post code on the forums the right way.
Ah, the problem might be that the X value needs to be a multiple of 8(or 4?).
Try this:
Code: Select all
#include <SPI.h> //imports the SPI library
#include <Gamebuino.h> //imports the Gamebuino library
Gamebuino gb; //creates a Gamebuino object named gb

static unsigned char PROGMEM sprite[] =
{
  16,6,
  B00011110,B00000000,
  B01010100,B10000000,
  B01000000,B10000000,
  B00111111,B00000000,
  B00010000,B00000000,
  B00000100,B00000000,
};

void setup(){
  gb.begin());
  //display the main menu
  gb.titleScreen(F("Dart Monkey Sprite"));
  gb.sound.playTick();
}
//the main loop
void loop(){
  while(true) {
    if(gb.update()){
    gb.display.drawBitmap(16,6,sprite);
    }
  }
}
//This is the program.
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: Gamebuino Library Issues

Postby rodot » Sat Feb 14, 2015 1:01 pm

Skyrunner, I'm sorry if it sounds a little harsh, please stop saying people what to do like you're a moderator of some kind. You're free to advise them when it's relevant though. By the way there is no rule that people have to use quotes (especially when not relevant).
Also, when you post code to help, please make sure it works first, because your code doesn't even compile.

TheSpikeFactory, your code doesn't compile for several reasons:

1 - Bytes can only be 8 bits long, for example B00001111. By the way this is just a way of writing it in its binary form, you can also write it in hexadecimal : 0x0F, which is more compact (in your source code, it doesn't make any difference once compiled). Plus, the bitmaps width has to be a multiple of 8. Also, the PROGMEM keyword should be the last one, you should use the keyword const, and you don't need the keyword static. You should not "type" your sprites by hand directly into the code, it's quicker to encode them using the bitmap encoder and will avoid you to make these mistakes.

2 - You can an extra closing bracket at the line
Code: Select all
gb.begin());


3 - You call gb.sound.playTick(); out of setup() and loop(). Functions can't be called anywhere like that.

Here is you code with the mentioned corrections :

Code: Select all
#include <SPI.h> //imports the SPI library
#include <Gamebuino.h> //imports the Gamebuino library
Gamebuino gb; //creates a Gamebuino object named gb

const byte sprite[] PROGMEM =
{
  8,6,
  B0011110,
  B10101001,
  B10000001,
  B01111110,
  B00100000,
  B00001000,
};

void setup(){
  gb.begin();
  //display the main menu
  gb.titleScreen(F("Dart Monkey Sprite"));
  gb.sound.playTick();
}

//the main loop
void loop(){
  while(true) {
    if(gb.update()){
      gb.display.drawBitmap(12,6,sprite);
    }
  }
}


As Skyrunner said, you can use the "code" tags on the forum for better formatting. You'll find the button right above the text area where you type your post, or you can manually write the tags
Code: Select all
[code]Your code here[/code]


I think you should read the examples provided with the library to understand syntaxing. There is several topics on the topic with links to learn the basics of C++ you might be interested in reading.
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Gamebuino Library Issues

Postby Montiey » Sat Feb 14, 2015 1:16 pm

you forgot a 0 in the sprite map on the first line! :P
Fix is below:
Here is you code with the mentioned corrections :
const byte sprite[] PROGMEM =
{
8,6,
B00111100,
B10101001,
B10000001,
B01111110,
B00100000,
B00001000,
};
User avatar
Montiey
 
Posts: 68
Joined: Sat Jan 17, 2015 5:38 pm

Re: Gamebuino Library Issues

Postby Montiey » Sat Feb 14, 2015 1:21 pm

Hmm.. I get a black screen when I run this. Same happens for my other game I tried to make. Any clues to common problems? Other games run fine, but anything that comes out of the arduino IDE doesn't work for me.
User avatar
Montiey
 
Posts: 68
Joined: Sat Jan 17, 2015 5:38 pm

Re: Gamebuino Library Issues

Postby TheSpikeFactory » Sat Feb 14, 2015 1:55 pm

The code works now. Thanks R0D0T! ;) However, is there a way I can convert a .ino file into a .hex file?
TheSpikeFactory
 
Posts: 23
Joined: Wed Feb 11, 2015 11:42 pm

Re: Gamebuino Library Issues

Postby rodot » Sat Feb 14, 2015 4:26 pm

.ino is the source code of you game, you have to compile it to get the binaries in .hex format. It's explained on the Getting Started page.
You should start from working examples which are close to what you are trying to do, and change things one by on and see if that works. This way, you always know where the problem comes from ;)
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Gamebuino Library Issues

Postby Skyrunner65 » Sat Feb 14, 2015 4:28 pm

Sorry Rodot. I was just trying to tell him how to use the "Code" tags correctly.
Ah, and I had a whole post about how to do so.
Me and forgetting things...
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

PreviousNext

Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 5 guests

cron