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

Author Topic: can't set sfVector2f in 2.1?  (Read 5063 times)

0 Members and 1 Guest are viewing this topic.

Onurb

  • Newbie
  • *
  • Posts: 2
    • View Profile
can't set sfVector2f in 2.1?
« on: May 07, 2014, 01:01:50 am »
first of all thanks for development with C sfml, appreciate it too much; however it seems i am in need of some help!

every time i type:

sfVector2f v1(100.f,100.f);

or anything of the sort; and i try compiling, this is what i get

1>sfml_test2.c(20): error C2275: 'sfVector2f' : illegal use of this type as an expression
1>          C:\Program Files (x86)\CSFML-2.1\include\SFML/System/Vector2.h(64) : see declaration of 'sfVector2f'


how do i define a new vector then? anybody help me? it seems it is an illegal use of the type as an expression what i am doing but; why?
the usage in the documentation reads:

http://www.sfml-dev.org/documentation/2.1/classsf_1_1Vector2.php

sf::Vector2f v1(16.5f, 24.f);

that's the example code.

i just don't get it :S i can't make the stuff move without this; and setX doesn't work it seems;
i can't set make the 2 floats into a vector no matter what the manual says!!! sure could use a hand  :-\

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: can't set sfVector2f in 2.1?
« Reply #1 on: May 07, 2014, 02:16:44 am »
It's clear what the problem is...

You are trying to create a instance of a class in the C language. Class does not exists in C.

Onurb

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: can't set sfVector2f in 2.1?
« Reply #2 on: May 07, 2014, 02:41:02 am »
alright thanks my friend i suspected something like that :P

so how do i input 2 floats in the form of a sfVector2f ?? that's what i'm trying to figure out

every time i try to do this i fail, and i can't move my instances by setX or setY commands those don't seem to work either  >:(

sorry for being such a newb, last time i programmed it was C# and i think that has classes.. haven't touched C in a few years at least


this doesn't work either:

sfCircleShape_setPosition(shape,(sfVector2f){wmode.width/2.0f - radius, wmode.height/2.0f - radius})

although i am pretty sure it worked in 2.0? at least one forum claims it did for CSFML 2.0

how do i feed the circleshape_setposition function my set of floats to update it's position? :S i'm baffled lol something definitely eludes me here
« Last Edit: May 07, 2014, 03:59:05 am by Onurb »

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: can't set sfVector2f in 2.1?
« Reply #3 on: May 07, 2014, 06:16:10 am »
It's been a while since I programmed in C ( I now program in C++11 ).

 If sfVector2f is a struct (which is probably the case), you can use an initializer list

sfVector2f Vector = { floatX, floatY };
 

for the other part:

sfCircleShape_setPosition(shape,(sfVector2f){wmode.width/2.0f - radius, wmode.height/2.0f - radius})
 

I can not tell. Sorry.


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: can't set sfVector2f in 2.1?
« Reply #4 on: May 07, 2014, 07:50:37 am »
No, you can't instanciate C structures in the middle of an expression. Unless you create a function that does it.

sfVector2f vector(float x, float y)
{
    sfVector2f v = {x, y};
    return v;
}

func(..., vector(1, 2), ...);
Laurent Gomila - SFML developer

 

anything