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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Jimicro

Pages: [1] 2 3
1
General / Handling time to delay?
« on: January 09, 2011, 08:33:29 pm »
Hi all.

I have a little game with a shooting feature I want to hold down a button to shoot but I don´t want it to shoot all the time, so can I use sf::Clock to just make it wait between all generating shots?

2
Graphics / use shapes in vector
« on: January 04, 2011, 11:14:29 pm »
Quote from: "DevilWithin"
circles.push_back(new Circle());

The new Circle object already contains a sf::Shape as a private member, even though it doesn't have an actual Circle associated with it.

I don't know your goal with that, but you should rethink your design, a lot of weird things there :P


I have

Code: [Select]

void Circle::generateCircle()
{
    Circle* circle = new Circle;
    circle->sf::Shape::Circle(100, 50, 50, sf::Color::Red);
    circles.push_back(circle);
}



but it doesn´t save the attributes to the vector, I dont even know if it is possible to save them in vectors.

I need more than one circle and I thought the best way to stack them where in a vector.

3
Graphics / use shapes in vector
« on: January 04, 2011, 10:05:46 pm »
I have a problem.

I have a class method where I declare a new Shape. i want to stack this in a vector.

Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>

class Circle : sf::Shape
{
    private:
    sf::Shape circle;
    int radius;
    std::vector <Circle*> circles;
    int x;
    int y;
    public:
    void generateCircle();
    void setValues(int x, int y);
    void draw(sf::RenderWindow& App);
    Circle();
};



and the method

Code: [Select]


void Circle::generateCircle()
{
    Circle* circle = new Circle;
    circles->sf::Shape ?
    circles.push_back(circle);
}

how can I declare the shape in to the vector?

4
Graphics / Draw sprite using vector
« on: December 30, 2010, 01:57:06 pm »
Quote from: "DevilWithin"
Code: [Select]
void Bullet::move(int x, int y)
{
    for(unsigned int i = 0; i < bullets.size();  i++){
        bullets[i]->Move(x, y);
    }
}


That should do, to move ALL the bullets : )


THX a lot for a fast answer :D I belive that saved my day :D

5
Graphics / Draw sprite using vector
« on: December 30, 2010, 01:41:00 pm »
I solved it.

Now it´s just that how to move the bullet/sprite;

Code: [Select]

void Bullet::generateBullet()
{
    Missile* sprite = new Missile;
    sprite->SetImage(Image);
    sprite->Resize(300, 200);
    move();
    bullets.push_back(sprite);
}
//Here is the problem... I can´t use the sprite above in the next method.

//x = 20; y = 0;
void Bullet::move()
{
    sprite.Move(x, y);
}

void Bullet::draw(sf::RenderWindow& App)
{
    for(unsigned int i = 0; i < bullets.size(); i++)
    {
        App.Draw(*bullets[i]);
    }
}


6
Graphics / Draw sprite using vector
« on: December 30, 2010, 11:35:54 am »
Quote from: "DevilWithin"
If the vector is declared as vector<Sprite*>, it will expect Sprite* objects to be added.

If your Bullet class is not inherited from Sprite, it has no relation to Sprite class, therefore, it can't be inserted.

Possible fix:

When declaring Bullet class: class Bullet : public Sprite{..};

Another possible fix:

Instead of declaring the vector as vector<Sprite*>, declare it as vector<Bullet*>

To render everything, you can do something like this:

Code: [Select]
for(unsigned int i = 0; i < bullets.size(); i++){
          App.Draw(bullets[i]);
}


Note: it will only work if the object "bullets" is a Sprite, or inherits from Sprite.

Hope it helps ;D


How do I inherits a vector to a Sprite ? I have declared the bullet class: class Bullet : public sf::Sprite

and the vector to std::vector<Bullet> bullets; in the class.

But then drawing it just don´t make it with App.Draw(bullets)

do I have to declare it in some other way? or in the class method somewhere?

7
Graphics / Draw sprite using vector
« on: December 29, 2010, 09:21:32 pm »
Hello!

I am trying to use std::vector stl too make a little shootergame. But I don´t know how to save a sprite to a vector.

I have
Code: [Select]

#include "Sprite.h"

Bullet::Bullet()
{
    x = 100;
    y = 100;
    if(!Image.LoadFromFile("bullet.jpg"))
    {
        //Error
    }
}

void Bullet::shoot()
{
    Bullet* bullet1 = new Bullet;
    bullet1->SetImage(Image);
    bullets.push_back(bullet1);
}

void Bullet::drawBullet()
{
    bullet.SetImage(Image);
}

void Bullet::generateBullet()
{
    Bullet* bullet = new Bullet;
    bullets.push_back(bullet);

}
void Bullet::draw(sf::RenderWindow& App)
{
    App.Draw(bullet);
}



But the I can´t save the file to the vector who are vector<Sprite*> bullets; in bullet class.

I want to App.Draw(bullets);

What do I need to do?

8
Window / Many events
« on: February 25, 2010, 12:15:38 am »
I finally solved it:D

The problem was that I didn´t know where I should put the cScreen class, and I didn´t know that it was suppose do be called like the public Screen

So now its called class cScreen and public Screen, and it doesn´t say so in the tutorial, maybe it´s some kind of linking problem. But know it works perfect. and hopefully now I can make my game.

Thanks for ther help anyway :)

9
Window / Many events
« on: February 24, 2010, 11:18:47 pm »
Quote from: "gsaurus"
Code: [Select]
class screen_0: public Screen

Code: [Select]
//Screens preparations
    screen_0 s0;
    Screens.push_back (&s0);


Quote
error: no matching function for call to `std::vector<cScreen*, std::allocator<cScreen*> >::push_back(screen_0*)'
(...)
note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cScreen*, _Alloc = std::allocator<cScreen*>]


The error says it. Seems that you have a class named "cScreen", the error is saying that your Screens vector is of type std::vector<cScreen*>, and you're trying to add an element of type screen_0* (which base class is of type Screen, and not cScreen. Do you have a class cScreen and another named Screen  :?:


I have three classes, screen_0, screen_1 and cScreen

I have five files. main.cpp, screen.hpp, screens.hpp, screen_0.hpp, screen_1.hpp

10
Window / Many events
« on: February 24, 2010, 08:41:44 pm »
I have tried a lot now and I don´t gets it to work.

Code: [Select]
   //Screens preparations
    screen_0 s0;
    Screens.push_back (&s0);


There I get an error.

Quote
D:\Programmering\Screens\main.cpp||In function `int main(int, char**)':|
D:\Programmering\Screens\main.cpp|22|error: no matching function for call to `std::vector<cScreen*, std::allocator<cScreen*> >::push_back(screen_0*)'|
C:\Program\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_vector.h|557|note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cScreen*, _Alloc = std::allocator<cScreen*>]|
||=== Build finished: 1 errors, 0 warnings ===|

This error I only get when I write:
Code: [Select]
class screen_0: public Screen
and if I get this code
Code: [Select]
class screen_0: public Screen
{
private:
    int alpha_max;
    int alpha_div;
    bool playing;
public:
    screen_0 (void);
    virtual int Run (sf::RenderWindow &App);
};


Here I get an error to if I write public Screen after the class.
Quote

D:\Programmering\Screens\screen_0.hpp|5|error: expected class-name before '{' token|
D:\Programmering\Screens\main.cpp||In function `int main(int, char**)':|
D:\Programmering\Screens\main.cpp|22|error: no matching function for call to `std::vector<cScreen*, std::allocator<cScreen*> >::push_back(screen_0*)'|
C:\Program\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_vector.h|557|note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cScreen*, _Alloc = std::allocator<cScreen*>]|


I don´t now what to do, can it be some linking error?

11
Window / Many events
« on: February 21, 2010, 12:35:34 am »
Quote from: "gsaurus"
Quote from: "Jimicro"
I only want a menu and don´t want to load the game before the menu. You now like a real game so I don´t will see the game in the background while I am in the menu.


Perhaps you want something like this?


yeah, but I didn´t got it to work :(

So I hopefully thought it was some easier way to handle many events.

12
Window / Many events
« on: February 20, 2010, 07:28:35 am »
Quote from: "Nexus"
What do you want to achieve by doing this? There is probably another way. ;)

You normally only have one sf::Event instance, which doesn't live very long. Some related code in the main loop might look as follows:
Code: [Select]
sf::Event event;
while (renderWindow.GetEvent(event))
{
    // react to events here
}
// after the loop, the event isn't interesting anymore


okey, thx I only want a menu and don´t want to load the game before the menu. You now like a real game so I don´t will see the game in the background while I am in the menu.

But thanks I shall see what I can do now. And hopefully it will work.:)

13
Window / Many events
« on: February 18, 2010, 02:15:47 am »
Hello

Is there away you can have many different events?

Like different classes and functions.

sf::Event Run;
sf::Event Meny;

Like that?

14
General discussions / SFML 1.6 released soon
« on: January 28, 2010, 11:10:01 pm »
Quote from: "Laurent"
Quote
I don´t know if it´s already fixed but when I am using font I get this memory error

Can you tell me more about this error?


It says something like this, I shall translate the best I can.

program-exe - Programfail

The instruction on "0x6903a33a" referd to th memory on "0x00000054". It didn´t perform a memory arrangment. This error returned: The memory could not be "read".

It pops up everytime a close the window when I draw use/draw a font.

15
General discussions / SFML 1.6 released soon
« on: January 28, 2010, 07:46:53 pm »
I don´t know if it´s already fixed but when I am using font I get this memory error. Maybe it should be fixed :)

Pages: [1] 2 3
anything