Hello! I am trying to learn how to create a simple game following some nice tutorials on Youtube. I have two questions:
1. There is nothing wrong with the "moving code" I use. It does exacly what I tell it to do. I want to learn how to NOT make the player stop moving to the left or right when I click the spacebutton to shoot
void Player
::keyPressEvent(QKeyEvent *event
){ // move the player left and right
if (event->key() == Qt::Key_Left){
if (pos().x() > 0)
setPos(x()-10,y());
}
else if (event->key() == Qt::Key_Right){
if (pos().x() + 100 < 800)
setPos(x()+10,y());
}
// shoot with the spacebar
else if (event->key() == Qt::Key_Space){
// create a bullet
Projectile * projectile = new Projectile();
projectile->setPos(x()+35,y());
scene()->addItem(projectile);
}
}
void Player::keyPressEvent(QKeyEvent *event){
// move the player left and right
if (event->key() == Qt::Key_Left){
if (pos().x() > 0)
setPos(x()-10,y());
}
else if (event->key() == Qt::Key_Right){
if (pos().x() + 100 < 800)
setPos(x()+10,y());
}
// shoot with the spacebar
else if (event->key() == Qt::Key_Space){
// create a bullet
Projectile * projectile = new Projectile();
projectile->setPos(x()+35,y());
scene()->addItem(projectile);
}
}
To copy to clipboard, switch view to plain text mode
2. How to play add and play a simple .gif-animation. I use the following code (a sample) with no errors, but nothing appears in my window:
QMovie *movie
= new QMovie("C:/Users/Technopia/Desktop/banana.gif");
//Everybody love bananas :cool: gif_anim->setMovie(movie);
movie->start();
QLabel *gif_anim = new QLabel();
QMovie *movie = new QMovie("C:/Users/Technopia/Desktop/banana.gif"); //Everybody love bananas :cool:
gif_anim->setMovie(movie);
movie->start();
To copy to clipboard, switch view to plain text mode
Thanks
Bookmarks