Hello
thank you for answering, and regarding the mousePressEvent(), its being called in the game class:
This is the code :
{
if(event->buttons() == Qt::RightButton && in_room!="menu"){
QLineF ln
(event
->pos
(),player
->pos
());
int angle = -1 * ln.angle() + 460;
int tmp = angle + 80;
if(tmp>360)
tmp-=360;
if(angle > 360)
angle += -360;
player->setPlayerRotation(angle,tmp);
player->setDestination(t);
}
}
void Game::mousePressEvent(QMouseEvent *event)
{
if(event->buttons() == Qt::RightButton && in_room!="menu"){
QLineF ln(event->pos(),player->pos());
int angle = -1 * ln.angle() + 460;
int tmp = angle + 80;
if(tmp>360)
tmp-=360;
if(angle > 360)
angle += -360;
player->setPlayerRotation(angle,tmp);
QPointF t(event->pos());
player->setDestination(t);
}
}
To copy to clipboard, switch view to plain text mode
I tried putting :
QPointF t
(mapToScene
(event
->pos
()));
QPointF t(mapToScene(event->pos()));
To copy to clipboard, switch view to plain text mode
But it still doesn't work...
And yeah they are both QGraphicsItem instances in the scene, here is the code if helps :
Land and Water files ( both are the same just the namings are different )
#ifndef LAND_H
#define LAND_H
#include <QObject>
#include <QGraphicsPixmapItem>
Q_OBJECT
public:
private:
};
#endif // LAND_H
#ifndef LAND_H
#define LAND_H
#include <QObject>
#include <QGraphicsPixmapItem>
class Land: public QObject, public QGraphicsPixmapItem{
Q_OBJECT
public:
Land(QGraphicsPixmapItem *parent=NULL);
private:
QString file_name;
};
#endif // LAND_H
To copy to clipboard, switch view to plain text mode
.cpp
#include "land.h"
{
file_name = ":/Images/Land.png";
}
#include "land.h"
Land::Land(QGraphicsPixmapItem *parent)
{
file_name = ":/Images/Land.png";
setPixmap(QPixmap(file_name));
}
To copy to clipboard, switch view to plain text mode
I don't know how to make my mouse event ignore those two classes when pressing right click on them ( so that its like i'm trying to access scene only and get coordinate from it )... I tried looking for the solution on google ( ignore() functions and so on ) and i still have no idea...
Bookmarks