Make my sprite animate and move

(Suzanna Pearce) #1

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?

(Suzanna Pearce) #2

(Erwin) #3

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

(Suzanna Pearce) #4

I added that in but he still isnt moving

(Erwin) #5

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);

(Suzanna Pearce) #6

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?

(Erwin) #7

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

(Suzanna Pearce) #8

I will have a look at that tutorial too.

(Celine) #9

This MAY also help a little, its @JO3RI’s article in the Vol 4 Arduboy Magazine:

(Suzanna Pearce) #10

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

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?

(Pharap) #11

Not without seeing the exact code you used.

(Cody) #12

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; }

(Suzanna Pearce) #13

@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 <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 JUMP ;

Arduboy2 arduboy;
Sprites sprites;
byte frame = 0;

void setup() {
  //Set-up here
void loop() {
  if (!(arduboy.nextFrame())) return;
  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)){
      spritestate = FLY_RIGHT;
      playerisflying = true;
    else spritestate = WALK_RIGHT;
    playeriswalking= true;
  //else if JUMP AND WALK LEFT
  if (arduboy.justPressed(B_BUTTON)){
    spritestate = JUMP;
    playerisflying = true;
  switch (spritestate){
   case STAND_STILL :
   sprite.drawPlusMask(playerX, PlayerY, Bertie_idle_R,frame )
   playerisstanding = true;
    case WALK_RIGHT:
    sprite.drawPlusMask(playerX, PlayerY, Bertie_walk_animated_R, frame)
    playeriswalking = true;
    case FLY_RIGHT:
    sprite.drawPlusMask(PlayerX, PlayerY, Bertie_fly_animate_R,frame)
    playerisflying = true;
    //case walk left&jumpleft

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.

(Scott) #14

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

(Scott) #15

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

enum {

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.

(Scott) #17

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;

(Daniel) #18

lol i do scratch to and am also a complete begginer