我目前正在使用SFML 2.0创建游戏。基本上,这是一个自上而下的射击游戏,我很难理解下面的说法。按下空格键时会发射箭头。根据播放器精灵(archSprite)面对的方式,有四个语句。由source.y确定,此函数计算得出

enum DirectionKeys { Up, Left, Down, Right};

sf::Vector2i source(0, 0);
int getCellY(DirectionKeys direction)
{
    return (direction*64);
}


我遵循的逻辑是

int dir = source.y/64;


会找出我正在使用的Spritesheet朝向Sprite的方向0 =向上1 =左2 =向下3 =右此语句对除向右射击以外的所有内容均正确射击有人能弄清楚为什么我向右的箭头向下射击并箭头不旋转?就像关于正确射门的陈述被一起忽略了。任何人都可以请教吗?

#include "Game.h"
#include "Tilemap.h"
#include <SFML\Graphics.hpp>
#include <iostream>



 if(keypress == sf::Keyboard::Space && keyPressed)
 {
 int tblt = this->_game_data.curr_bullet;
 this->_arr_bullet_data[tblt].active        = true;

 //every 100th bullet it is set to the up rotation
 int dir = source.y/64;

 if (dir == 0)
 {
    _arr_bullet_spr[tblt].rotate(90);
    this->_arr_bullet_data[tblt].startpos     = this->archSprite.getPosition() + sf::Vector2f(64,-42);
    this->_arr_bullet_data[tblt].direction  = sf::Vector2f(0,-1);
 }
 else if (dir == 1)
 {
    _arr_bullet_spr[tblt].rotate(360);
    this->_arr_bullet_data[tblt].startpos     = this->archSprite.getPosition() + sf::Vector2f(-22,0);
    this->_arr_bullet_data[tblt].direction  = sf::Vector2f(-1,0);
 }
 else if (dir = 2)
 {
    _arr_bullet_spr[tblt].rotate(270);
    this->_arr_bullet_data[tblt].startpos     = this->archSprite.getPosition() + sf::Vector2f(0,96);
    this->_arr_bullet_data[tblt].direction  = sf::Vector2f(0,1);
 }
 else if (dir = 3)
 {
    _arr_bullet_spr[tblt].setRotation(180);
    this->_arr_bullet_data[tblt].startpos = this->archSprite.getPosition() + sf::Vector2f(0,0);
    this->_arr_bullet_data[tblt].direction  = sf::Vector2f(1,0);
 }

 this->_arr_bullet_spr[tblt].setPosition(this>_arr_bullet_data[tblt].startpos);
 this->_game_data.curr_bullet++;
 }


非常感谢

最佳答案

if(dir = 2)if(dir = 3)必须分别是if(dir == 2)if(dir == 3)

关于c++ - SFML游戏中第4条射击陈述不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29050600/

10-11 17:59