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 - smguyk

Pages: 1 2 [3] 4 5 6
31
Graphics / Is there a better way to make a minimap?
« on: November 10, 2014, 09:48:04 am »
I'm making a 2d platformer and I'd like to have a minimap. I saw this tutorial (see the bottom of the linked anchor) where the world is drawn to a view, and then it's drawn again but to a smaller view, the minimap.

Is there a better way to do it? It seems like it's not very efficient to draw the world twice? Or am I overthinking it

32
Graphics / Why is drawing my sf::VertexArray so CPU-extensive?
« on: October 20, 2014, 06:41:58 pm »
I am using the code from the tutorial for my game's tilemap.

The tilemap of the test level of my game only has 17 * 20 tiles each 32x32 pixels (and I'm planning to add a whole lot more tiles) but the CPU usage goes to 25% when drawing the vertex array.

I call drawTiles(*window); to draw it which is just a member function of the tilemap class. The function is

void TileMap::drawTiles(sf::RenderTarget &target) {
  sf::RenderStates states = sf::RenderStates::Default;
  states.transform *= getTransform();
  states.texture = &tilesTexture_;
  target.draw(tilesVertexArray_, states);
}

I used the Visual Studio Performance Wizard to see what's causing the heavy CPU usage, and it says it's the vertex array draw call.

Indeed, when I comment out the drawTiles(*window); to no longer draw the tilemap, the CPU goes down to 0%, even with no framerate limit.

What am I doing wrong, please??

33
Thank you!

You're right, it was the dimensions_ which I forgot to set. It's working now

34
In my 2D platformer I am passing the player's current view to the entity manager, so I only draw the entities that are currently in view.

I pass the following sf::FloatRect (currentView_ is just an sf::View):
sf::FloatRect(
  currentView_.getCenter().x - currentView_.getSize().x / 2,
  currentView_.getCenter().y - currentView_.getSize().y / 2,
  currentView_.getSize().x,
  currentView_.getSize().y
)

When I then use sf::FloatRect.intersects it doesn't draw the entities, but when I use sf::FloatRect.contains it draws them just fine.

void EntityManager::drawEntities(sf::RenderTarget &renderTarget, sf::FloatRect &rect) {
  // Doesn't work:
  for (std::vector<Entity>::iterator i = entities_.begin(); i != entities_.end(); ++i) {
    if (rect.intersects(i->getRect()) {
      renderTarget.draw(*i);
    }
  }

  // Works:
  for (std::vector<Entity>::iterator i = entities_.begin(); i != entities_.end(); ++i) {
    if (rect.contains(i->getRect().left + i->getRect().width / 2, i->getRect().top + i->getRect().height / 2)) {
      renderTarget.draw(*i);
    }
  }
}

In case it's needed, the function getRect() returns the entity's float rect:

sf::FloatRect Entity::getRect() {
  return sf::FloatRect(position_.x, position_.y, dimensions_.x, dimensions_.y);
}

The problem with it not working is that I don't want to check if only the entity's center is within the current view, but rather if ANY POINT of the entity's rect is.

Could someone please help me?

35
General / Re: Collision... yer driving me crazy
« on: August 29, 2014, 08:19:06 am »
Can't you just use intersects() and set the rect's new position based on its x/y velocities?

if (rect.getGlobalBounds().intersects(M.getGlobalBounds())) {
  // set position based on current velocity
}

and player::collision's parameter should be (mob &M)

36
Graphics / Re: Does SFML delete sprites that are drawn over?
« on: August 27, 2014, 03:14:46 pm »
off-topic but here are a few things I'd like to say

- your sf::Event::Resized case doesn't have a break. also the default statement is missing (it's optional but should always be there and if it's left out on purpose there should be a comment about it)

- is there a reason you are creating the textures/sprites and loading the textures in every loop iteration? put it outside. also there's no error handling

- your input checking is weird. also I recommend you don't mix events and real-time input the way you do in that code

- you should arrange that code better. that includes avoiding global sf variables, using classes / member variables & functions, organising code like input & draw calls instead of scattering it throughout the entire program

- in connection with the above point, in general try to code more object oriented especially in a project like yours

- it's always nice to be consistent in variable naming and code indentation, it will make everything much better. also I personally avoid things like using namespace std, just use std::

if anyone wants to object to any of the above feel free to!

37
Graphics / Re: Card flipping animation
« on: August 27, 2014, 12:43:29 pm »
@Mario

Your example looks neat.

I put together something similar based on Stauricus's answer but it's not as good as your code. I'll use it if you don't mind?

By the way, your code won't compile for me. In lines 67 and 75 (float scale = ...) I had to add .asSeconds() to all the time variables but now it's working fine.

38
Graphics / Re: Card flipping animation
« on: August 27, 2014, 01:56:19 am »
you could shrink the card sprite, creating an illusion.


it's just an idea, you'd have to fix and finish the code.

Thanks, that actually looks pretty good. I'll see if I can use that and report back

I think this would be possible to get an "acceptable" effect using a VertexArray and animating the corners elliptically, depending on your level of acceptability as there would be no perspective and both sides must be animated equally as a mirror otherwise there will be texture distortion.

Yeah but I reckon it's going to be a lot of work

39
Graphics / Re: Card flipping animation
« on: August 26, 2014, 09:01:51 am »
Hm, I see, thanks. I'll look into OpenGL then.

40
Graphics / Card flipping animation
« on: August 26, 2014, 08:48:36 am »
I'm making a memory game and I'd like to animate flipping over a card. A card is just an sf::Sprite.

The card (or: sprite) should revolve around its own axis, maybe something like this http://davidwalsh.name/demo/css-flip.php but I haven't found any code that could help me.

sf::Sprite::rotate exists and it rotates the sprite, but I need a rotation around the sprite's y-axis.

Can someone please help me?

41
Thank you for this extensive answer

I experienced no performance drops, I was just trying to optimise rendering the vertices like I do with other stuff, e.g. drawing objects only if they're on-screen.

For now I'll stick with a single vertex array then.

42
Graphics / sf::VertexArray: Draw only vertices within certain bounds
« on: July 06, 2014, 06:25:42 am »
I am using the code from the tutorial to draw a tile map and it works just fine.

Now, my level vertex array is getting pretty big and I only want to render tiles within certain bounds (those tiles that are currently in the view) instead of drawing all of them. The tutorial code has the following lines to draw the whole vertex array:

states.transform *= getTransform();
states.texture = &m_tileset;
target.draw(m_vertices, states);

How would I modify that code to draw only vertices that are, say, in an sf::IntRect(x, y, w, h) which I'd pass as a parameter?

I seriously have no idea. Could you please help me / start me off?

Thanks!

43
General / Mobile development (iOS etc.)
« on: June 25, 2014, 03:56:17 am »
Hi!

I haven't found any info on whether it's possible to port to mobile devices, for example iOS. I only found this thread and some posts scattered throughout the SFML forum.

Is it possible yet to compile for iOS and the like, and if so, can anyone direct me to some resources how one would go about that? Google wasn't really helpful...

Thanks

Edit:
It says on the main page "and soon Android & iOS". No idea how I could overlook that.
Does anyone know how the development is going for those platforms / the estimated release date?

44
Thanks guys.

I'll go with the VM for Linux then, and ditch Mac entirely

45
Is it possible to compile for Mac/Linux using MS Visual Studio or any other compiler on Windows?

I don't have Mac or Linux but want my game for those platforms too

Pages: 1 2 [3] 4 5 6