Make my sprite animate and move

Only got my Arduboy on friday and i am very new to coding .

I have created a little bird and i have read the help and info on making a guy walk so now he is animated, before this i had him moving across the screen up and down etc,

1 i cant seem to get him to be animated and move around the screen ?

2 how can i change the action so if i wanted him to be still untill i press the move arrow and then walk ( and eventually
jump (fly) when i press A) ?

would it be helpful if i put the code i have so far on here?

1 Like

You forget to put the position here:
sprites.drawSelfMasked(0, 0, player, frame);

I added that in but he still isnt moving

Yes, because you forget to put the position here:
sprites.drawSelfMasked(0, 0, player, frame);

After adding the position, should look like this:
sprites.drawSelfMasked(playerx, playery, player, frame);

1 Like

Thankyou! complete novice, only started coding on friday ( except for scratch jr and microbit for teaching)

do you know how you change the sprite for different actions … so if i hit button A he will look like he is flying?

1 Like

Sure but I recommend you to follow @crait tutorial:

For the jump, if is only an animation you can use a toggle
bool jumping=false;

And switch it to true when the button is press. Then in the animation, change the current frame for the one jumping if that toggle is set to true

2 Likes

thanks!
I will have a look at that tutorial too.

This MAY also help a little, its @JO3RI’s article in the Vol 4 Arduboy Magazine: https://issuu.com/arduboymag/docs/arduboy_magazine_vol4_final_single/18

1 Like

sooo I. have had a go at using this code.[quote=“Celinebins, post:9, topic:3628”]
This MAY also help a little, its @JO3RI’s article in the Vol 4 Arduboy Magazine
[/quote]

to move my animaltion and I have got stuck , it says I cannot use STAND_STILL_R as a constant.
I know i have done somthing wrong above, any ideas what it could be?

Not without seeing the exact code you used.

Also try

arduboy.clear(); delay(50); If(arduboy.pressed(A_BUTTON)) { count = 1; } if(count == 1) { arduboy.drawBitmap(0,0,walking1,16,16,WHITE); count = 2; } if(count == 2) { arduboy.drawBitmap(0,0,walking2,16,16,WHITE); count = 1; }

@Zanners59, I (@MLXXXp) have edited this post to properly format the code by enclosing it in ```cpp on a line at the start and ``` on a line at the end.

#include"BITMAP.H"
#include <Arduboy2.h>
#include <Arduboy.h>
//Variables declared here
int spritestate = 0;
int playerX = 5;
int playerY = 10;
int justpressed = 0;
int playeriswalking = false;
int playerisjumping = false;
int playerisstill= false;
int playerisflying = false;
int STAND_STILL ;
int WALK_RIGHT ;
int FLY_RIGHT ;
int JUMP ;



Arduboy2 arduboy;
Sprites sprites;
byte frame = 0;

void setup() {
  arduboy.begin();
  //Set-up here
  arduboy.clear();
  arduboy.setFrameRate(30);
}
void loop() {
  if (!(arduboy.nextFrame())) return;
 arduboy.clear();
  sprites.drawSelfMasked(playerX, playerY, Bertie_idle_R , frame);
  if (arduboy.everyXFrames(3)) frame++; 
  spritestate = STAND_STILL;
  if (arduboy.justPressed(RIGHT_BUTTON)){
    playeriswalking = true;
    playerX --;
    if(arduboy.justPressed(B_BUTTON)and (RIGHT_BUTTON)){
      playerY--;
      spritestate = FLY_RIGHT;
      playerisflying = true;
    }
    else spritestate = WALK_RIGHT;
    playeriswalking= true;
  }
  //else if JUMP AND WALK LEFT
  if (arduboy.justPressed(B_BUTTON)){
    playerY--;
    spritestate = JUMP;
    playerisflying = true;
  }
  switch (spritestate){
   case STAND_STILL :
   sprite.drawPlusMask(playerX, PlayerY, Bertie_idle_R,frame )
   playerisstanding = true;
    break;
    case WALK_RIGHT:
    sprite.drawPlusMask(playerX, PlayerY, Bertie_walk_animated_R, frame)
    playeriswalking = true;
    break;
    case FLY_RIGHT:
    sprite.drawPlusMask(PlayerX, PlayerY, Bertie_fly_animate_R,frame)
    playerisflying = true;
    //case walk left&jumpleft
    }
  }
  arduboy.display();
}

please be aware that a am really new at this and i think there are probably other things that are wrong as well !!
Also Thanks to this amazing community who help out us newbies, you are amazing.

1 Like

You should only include the Arduboy2 library, not the Arduboy library.

Since the above are states, not intended to hold variable values, you should make them constants:

enum {
  STAND_STILL,
  WALK_RIGHT,
  FLY_RIGHT,
  JUMP
};

Using enum is an easy way of assigning incrementing values to each constant declared in the enumeration. STAND_STILL will be given a value of 0, WALK_RIGHT will equal 1, etc.

1 Like

If you’re only going to assign true or false to a variable, you should make it a boolean or bool. (boolean and bool are equivalent. boolean is the Arduino type name, bool is standard C++. Use what you prefer.)

boolean playeriswalking = false;
boolean playerisjumping = false;
boolean playerisstill = false;
boolean playerisflying = false;
1 Like

lol i do scratch to and am also a complete begginer

1 Like