Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Rect.Intersects trouble  (Read 4011 times)

0 Members and 1 Guest are viewing this topic.

dreadnought

  • Newbie
  • *
  • Posts: 8
    • View Profile
Rect.Intersects trouble
« on: January 19, 2012, 09:24:19 am »
Hey there,
i got some problem with a collision-test im doing at the moment. Also im still kinda noobish at C++ so i cant figure out whats wrong by myself. Hope you can help me.
Code works just fine without that Intersects Line.

Here is my (full) Code:

Code: [Select]

#include "stdafx.h"
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include <SFML\Window.hpp>


int main()
{
    // Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Collision-Test");//,sf::Style::Fullscreen);
const sf::Input& Input = App.GetInput();

// Rects

sf::Rect<int> HRect;
sf::Rect<int> ORect(200,200,240,240);

// Init Player (20x30px)
sf::Image HeroIMG;
sf::Sprite HeroSprite;
float Speed;
HeroIMG.LoadFromFile("data/img/hero.bmp");
HeroSprite.SetImage(HeroIMG);
HeroSprite.SetPosition(400.f, 300.f);
HeroSprite.SetCenter(11,22);
Speed=100.f;

// Init Rect (40x40px)
sf::Image RectIMG;
sf::Sprite Rect;
RectIMG.LoadFromFile("data/img/rect.bmp");
Rect.SetImage(RectIMG);
Rect.SetPosition(200.f,200.f);
    // Start game loop
sf::FloatRect RenderRect;
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
App.Close();

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            App.Close();

        }

// Update Player
float ElapsedTime = App.GetFrameTime();

sf::Vector2f Position=HeroSprite.GetPosition();
HRect.Left=Position.x;
HRect.Top=Position.y;
HRect.Right=Position.x+20;
HRect.Bottom=Position.y+30;


// Move the PlayerSprite
if (App.GetInput().IsKeyDown(sf::Key::A)) HeroSprite.Move(-Speed * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::D)) HeroSprite.Move( Speed * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::W))   HeroSprite.Move(0, -Speed * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::S)) HeroSprite.Move(0,  Speed * ElapsedTime);

if(HRect.Intersects(ORect))
{
HeroSprite.SetPosition(500,500);
}

        // Clear the screen (fill it with black color
        App.Clear();

// render Player
App.Draw(Rect);
App.Draw(HeroSprite);

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}



Error:

1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(104): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(102): Bei der Kompilierung der  Klassen-template der bool sf::Rect<T>::Intersects(const sf::Rect<T> &,sf::Rect<T> *) const-Memberfunktion
1>          with
1>          [
1>              T=int
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\glyph.hpp(54): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "sf::Rect<T>".
1>          with
1>          [
1>              T=int
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(104): error C2059: Syntaxfehler: '::'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(105): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(106): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(107): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(110): error C2065: 'Overlapping': nichtdeklarierter Bezeichner
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(110): error C2228: Links von ".Left" muss sich eine Klasse/Struktur/Union befinden.
1>          Typ ist ''unknown-type''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(110): error C2065: 'Overlapping': nichtdeklarierter Bezeichner
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(110): error C2228: Links von ".Right" muss sich eine Klasse/Struktur/Union befinden.
1>          Typ ist ''unknown-type''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(110): error C2065: 'Overlapping': nichtdeklarierter Bezeichner
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(110): error C2228: Links von ".Top" muss sich eine Klasse/Struktur/Union befinden.
1>          Typ ist ''unknown-type''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(110): error C2065: 'Overlapping': nichtdeklarierter Bezeichner
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(110): error C2228: Links von ".Bottom" muss sich eine Klasse/Struktur/Union befinden.
1>          Typ ist ''unknown-type''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sfml\graphics\rect.inl(113): error C2065: 'Overlapping': nichtdeklarierter Bezeichner

PS: Sorry for bad english and german-error logs (as i am german)

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
Rect.Intersects trouble
« Reply #1 on: January 19, 2012, 02:34:29 pm »
There must be something wrong in the project configuration, that code just works well for me with SFML 1.6 using CodeBlocks and MinGW

dreadnought

  • Newbie
  • *
  • Posts: 8
    • View Profile
Rect.Intersects trouble
« Reply #2 on: January 19, 2012, 03:23:34 pm »
But what could it be?
Under Linker->additional dependencies i got:
sfml-graphics-d.lib;sfml-window-d.lib;sfml-main.lib;sfml-system-d.lib;sfml-audio-d.lib;

under C++-> Preprocessor : SFML_DYNAMIC;

nothing more changed from standard values

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Rect.Intersects trouble
« Reply #3 on: January 19, 2012, 03:37:40 pm »
What's inside the "stdafx.h" header?
Laurent Gomila - SFML developer

dreadnought

  • Newbie
  • *
  • Posts: 8
    • View Profile
Rect.Intersects trouble
« Reply #4 on: January 19, 2012, 04:49:50 pm »
stdafx.h:
Code: [Select]
#pragma once

#include "targetver.h"

#define WIN32_LEAN_AND_MEAN             // Selten verwendete Teile der Windows-Header nicht einbinden.
// Windows-Headerdateien:
#include <windows.h>

// C RunTime-Headerdateien
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>


targetver.h:

Code: [Select]

#pragma once
#include <SDKDDKVer.h>


and by the way: im using SFML1.6

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Rect.Intersects trouble
« Reply #5 on: January 19, 2012, 04:54:23 pm »
What's the name (especially the extension) of your source file?
Laurent Gomila - SFML developer

dreadnought

  • Newbie
  • *
  • Posts: 8
    • View Profile
Rect.Intersects trouble
« Reply #6 on: January 19, 2012, 05:01:22 pm »
its simply "test.cpp"

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Rect.Intersects trouble
« Reply #7 on: January 19, 2012, 05:47:50 pm »
Ok I know what's wrong.

Quick fix: define the NOMINMAX macro before including stdafx.h.

Better fix: don't include <windows.h> if you don't need to.

Even better fix: don't use precompiled headers (stdafx.h) if you don't need to.
Laurent Gomila - SFML developer

dreadnought

  • Newbie
  • *
  • Posts: 8
    • View Profile
Rect.Intersects trouble
« Reply #8 on: January 19, 2012, 07:20:00 pm »
Laurent you rock!
You code this awesome SFML-thing AND solved my problem.
*thumbs up*
(i also will name all my kids after you)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Rect.Intersects trouble
« Reply #9 on: January 19, 2012, 09:48:37 pm »
Quote
i also will name all my kids after you

Hopefully they'll become as awesome as me 8)
:lol:
Laurent Gomila - SFML developer

 

anything