Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Sunsharior

Member Since 14 Dec 2013
Offline Last Active Today, 09:05 AM

Posts I've Made

In Topic: Rotating a sprite in SDL2?

17 March 2015 - 05:17 PM

With this simple snipet, you will be able to draw a sprite.

// for this to work, i will assume you already have a SDL_Renderer and a SDL_Window.
SDL_Texture *texture = IMG_LoadTexture(renderer, "image.png");

// if the texture was loaded.
if(texture)
{
    SDL_Rect rect = {0, 0, 32, 32}; // the rect is where you wants the texture to be drawn (screen coordinate).
    SDL_Rect crop = {0, 0, 16, 16}; // the crop is what part of the image we want to display.

    float angle = 180.0f; // set the angle.
    SDL_Point center = {8, 8}; // the center where the texture will be rotated.
    SDL_RendererFlip flip = SDL_FLIP_NONE; // the flip of the texture.

    // now, try to draw something
    int result = SDL_RenderCopyEx(renderer, texture, &crop , &rect, angle, &center, flip);
    
    if(result!= 0)
        std::cout << SDL_GetError() << std::endl;
}
else
    std::cout << Error << "Couldn't render texture." <<  std::endl;

Using this example, you will draw an image rotated 180 degree.

It will be drawn at 0,0 with a width of 32 and a height of 32. The crop is 16x16 and the rotation is 180 that is centered at 8,8.

 

I hope this help.

If you have errors, feel free to post it.


In Topic: Text Based RPG help

11 December 2014 - 02:12 PM

Like Josh Petrie said, you declared functions in a header file that were never defined elsewhere. I have enclosed 3 of your project's file code with the error fixed.

 

You will noticed a few things:

 

1. I have created the Prologue.cpp file and moved the content from Char info.cpp to it.

2. The prologue is now used as a class instead of static. See the modification i did to Main.cpp to notice it's scope remain inaffected.

3. The fonctions and member variables of the class Prologue are no longer static. Prologue.cpp now have the proper definition of thoses fonctions, and a constructor aswell.

4. The file Char info.cpp has been deleted.


In Topic: How should i process about embedding a SDL2 game into QT to make a level editor.

01 December 2014 - 11:54 AM

Thank you for your reply Dejaime. It helped me do the initial setup.

 

After fiddling this weekend, and doing additional researches, i've partially solved my problem. I'm not done yet but i've successfully draw something in QT using Sdl2. Now, what i'm missing is just the Inter-process communication between the QT application and my game. I should be able to do that during this week.

 

So, it's looking good, at the moment :).


In Topic: Culling points from a polygon.

29 August 2014 - 07:07 AM

Thank you. It worked like a charm!

Here is the code for anyone that could need it later.

 

#define EPSILON 0.0001f
//////////////////////////////////////////////////////////////////////////
//Culling mean removing unneeded vector.
void Cull(std::vector<CVector> &_val)
{
    if(_val.size())
    {
        for(int i = 0; i < static_cast<int>(_val.size());)
        {
            int n = i + 1 < _val.size() ? i + 1 : 0; //next
            int l = i - 1 >= 0 ? i - 1 : _val.size() - 1; //last
            
            if((SignedArea(_val[l], _val[i], _val[n]) * 0.5f) < EPSILON)
                _val.erase(std::remove(_val.begin(), 
                                       _val.end(), 
                                       _val[i]), 
                                       _val.end());
            else 
                i++;           
        }
    }   
}

//////////////////////////////////////////////////////////////////////////
//
float SignedArea( CVector _a, CVector _b, CVector _c )
{
    return ( (_b.x - _a.x) * (_c.y - _a.y)
           - (_c.x - _a.x) * (_b.y - _a.y) );
}

In Topic: SDL 1.2, moving window, objects falling through tiles

12 June 2014 - 10:49 AM

Hi too_many_stars,

 

there is not enough information to solve the problem without going into speculations.

 

1. Try posting code you think might be the culprit.

2. Add more information to the problem. Try to be as descriptive as possible.

3. Explain how your game work. What is normally supposed to happen when you move the game window?

4. Do you use other library or engin?

 

Since you mention SDL, i assume this is a simple 2D game. What kind of physic do you use?

 

As you can see, more information is needed.


PARTNERS