我目前正在使用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找出精灵所面对的方向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++;
}
非常感谢
答案 0 :(得分:1)
if(dir = 2)
和if(dir = 3)
必须分别为if(dir == 2)
和if(dir == 3)
。