About "Moving" question

I found when I was pressing “up down left right” fast, in a little odds the aircraft can’t move.
that’s the function:

void aircraft::move(){
leftsign = true;
rightsign = true;
upsign = true;
downsign = true;


Please tell me how can i do.

1 Like

Are you using mbed or EmBitz?

There doesn’t seem to be a problem with this bit of code,
do you have the rest of your code available?

Im using mbed, “white screen” seem to be my code problem. Solved problem when I changed other game file.
Thank you!

But “moving problem” cofused me yet.

Your code should be working.
It is most likely that your code problem is somewhere else.
I think you will have to show more of your code.

What is AIRCRAFT_SPEED defined as?
What type is xaxis?
Is move actually being called?

Thanks your hint, I think the problem where in display function.
when I only use single direction sign, Not the problem.
But I use two signs together, the problem will appear

void aircraft::display(){
if(upsign && leftsign){
upsign = false;
leftsign = false;
}else if(upsign && rightsign){
upsign = false;
rightsign = false;
}else if(downsign && leftsign){
downsign = false;
leftsign = false;
}else if(downsign && rightsign){
downsign = false;
leftsign = false;
}else if(upsign){
upsign = false;
}else if(downsign){
downsign = false;
}else if(leftsign){
leftsign = false;
}else if(rightsign){
rightsign = false;
}else {
upsign = false;
downsign = false;
leftsign = false;
rightsign = false;


Is your problem that the plane isn’t moving?
Or is your problem that the wrong sprite is being drawn?

If your problem is drawing the wrong sprite, then try this:

void aircraft::display() {
	if(upsign && leftsign) {
		Pokitto::Display::drawBitmap(xaxis, yaxis, aircraft_bmp[0]);
	} else if(upsign && rightsign) {
		Pokitto::Display::drawBitmap(xaxis, yaxis, aircraft_bmp[2]);
	} else if(downsign && leftsign) {
		Pokitto::Display::drawBitmap(xaxis, yaxis, aircraft_bmp[6]);
	} else if(downsign && rightsign) {
		Pokitto::Display::drawBitmap(xaxis, yaxis, aircraft_bmp[8]);
	} else if(upsign) {
		Pokitto::Display::drawBitmap(xaxis, yaxis, aircraft_bmp[1]);
	} else if(downsign) {
		Pokitto::Display::drawBitmap(xaxis, yaxis, aircraft_bmp[7]);
	} else if(leftsign) {
		Pokitto::Display::drawBitmap(xaxis, yaxis, aircraft_bmp[3]);
	} else if(rightsign) {
		Pokitto::Display::drawBitmap(xaxis, yaxis, aircraft_bmp[5]);
	} else {
		Pokitto::Display::drawBitmap(xaxis, yaxis, aircraft_bmp[4]);
	upsign = false;
	downsign = false;
	leftsign = false;
	rightsign = false;

unfortunately, my problem is the plane isn’t moving.
just likes the plane not moving when I fast press right button after pressing left button. in a little odds.

aircraft class.zip (1.8 KB)

This code all looks fine.

The only two reasons I can think that it wouldn’t be moving are:

  • the pokitto buttons aren’t being updated (i.e. Pokitto::Core::update() isn’t being called)
  • move isn’t being called.
  • clear is being called when it shouldn’t be

When left and right are pressed at the same time,
xaxis -= AIRCRAFT_SPEED; and xaxis += AIRCRAFT_SPEED; cancel out ((x - 4 + 4) == (x + 0) == x),
and the sprite is drawn facing left beccause:

}else if(leftsign){
}else if(rightsign){

That is just display problem.
But the plane still there when I only hold one direction sometimes. And I released the button and hold again, the plane can move.
I think that means some value not changed. Or the button’s electric noise???

It could be a hardware issue rather than a software issue.

Try drawing a marker on screen when each button is pressed.

  Pokitto::Display::fillRectangle(0, 32, 32, 32);
  Pokitto::Display::fillRectangle(32, 32, 32, 32);
  Pokitto::Display::fillRectangle(0, 0, 32, 32);
  Pokitto::Display::fillRectangle(0, 64, 32, 32);

If the rectangles match the plane movement, the problem is not with your code.
If rectangles do not match the plane, something else in your code is interfering with your plane.

the rectange not appeared when the plane stayed there when I reproduced the problem.
That means the hardware checks button isn’t pressed ???

In that case, it is probably either a hardware issue or a problem with the PokittoLib,
not a problem with your code.

Thank you and Wishing jonne notice it .

1 Like

@79859899 : you have to post the complete code / give me a link to the code. I need to see your main game loop.

Using buttons inside a game loop is not simple. You have to understand how the button functions work.

@Pharap : Pokitto::Buttons::upBtn() etc. is instantaneous. What is happening here is @79859899 is expecting a buffered behaviour.

In other words, the plane moves, but in one update cycle of the screen the plane comes back to its original position.

1 Like

I agree.
Seeing the whole code would be a lot more helpful than just small snippits.

Are you sure? That’s not the impression I was getting.

I thought the problem was that sometimes the buttons were being pressed but it wasn’t being registered, hence:

Thank you, Jonne and Pharap
This is my total sourse:

1 Like

I am not able to reproduce the issue / maybe I do not understand what you mean

@79859899 I have improved the button handling just a little bit.

Pokitto_Game_Lost_LPC11U68.bin (51.9 KB)

Right-click on PokittoLib folder in compiler, update PokittoLib and see if this removes any problem

I know it’s possible under certain circumstances to be holding one of the dpad directions and for it to not be registered as 1 in Pokitto::heldStates.
It’s not particularly common but it happens.

It’s hard to tell exactly what the circumstances are though, it happens occaisionally when pressing lots of dpad directions in quick succession.

When it happens, say for example left is held down but the corresponding entry in heldStates is 0, you’d still be able to get up and down to register by pressing on up and down without letting go of left, but left won’t register as 1 until you let go and press it again.

Originally I thought it was the dpad being unable to hold a button down under certain circumstances, but upon looking at the button code I’m beginning to suspect the issue could be that the Pokitto can only handle a certain number of interrupts at a time, and having too many at once causes some interrupts to be dropped from the queue.
(I tried marking heldStates as volatile as a precaution, but the button situation still happened.)

I have added code in mbed to clear opposite direction flag when other direction is pressed.

IMHO it helped. Try the binary above.

I will update the github also later today