-
Notifications
You must be signed in to change notification settings - Fork 51
Input
Zal0 edited this page Sep 13, 2021
·
4 revisions
Let's make our sprite move a little bit:
- Open SpritePlayer.c and include Keys.h and SpriteManager.h
- The KEY_PRESSED macro tells us if a key is pressed or not. Write the next code in the Update function:
if(KEY_PRESSED(J_UP)) {
THIS->y --;
}
- Compile and you should see your sprite moving upwards when pressing the up button
- Now, to do the full movement, this is how your SpritePlayer.c should look:
#include "Banks/SetAutoBank.h"
#include "Keys.h"
#include "SpriteManager.h"
void START() {
}
void UPDATE() {
if(KEY_PRESSED(J_UP)) {
THIS->y --;
}
if(KEY_PRESSED(J_DOWN)) {
THIS->y ++;
}
if(KEY_PRESSED(J_LEFT)) {
THIS->x --;
}
if(KEY_PRESSED(J_RIGHT)) {
THIS->x ++;
}
}
void DESTROY() {
}