2 Replies - 536 Views - Last Post: 12 March 2012 - 02:17 AM Rate Topic: -----

#1 EnlightenWebDesign  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 12-February 12

SMFL sprites and arrays

Posted 10 March 2012 - 09:09 AM

Hi guys, ive got a bit of coursework that im stuck on! :(

Basically i have to make a maze game, sprites etc using SFML and C++.

Now I've made an array to create the grid and mannaged to show 0,1,2,3's for different items on the map and show that in the console. It's got to the point where i need to show the sprites in the positions of the numbers and in the sfml screen not to console.

Heres the code i have but it doesn't show any of the different types of walls

int gridArray[10][10] = {
		{0,0,0,0,0,0,0,1,1,1},
		{1,1,2,1,0,0,0,1,0,0},
		{1,1,0,0,1,3,1,1,1,0},
		{0,1,0,0,0,0,0,0,0,0},
		{0,1,1,1,3,1,1,1,1,1},
		{0,0,0,0,0,0,1,0,0,0},
		{1,1,1,1,1,3,1,1,1,0},
		{0,0,0,0,0,0,0,1,0,0},
		{1,1,1,1,3,1,1,1,0,1},
		{0,0,0,0,0,0,0,0,0,0}
		
	};

	int gridVar = 0;

	for (int x = 0; x<10; x++){
			for (int y = 0; y<10; y++){
				gridVar=gridArray[x][y];
				
				switch (gridVar)
				{
				case 0:
					win.Draw(specialGemSprite);
					break;
				case 1:
					win.Draw(wallSprite);
					break;
				case 2:
					win.Draw(wallTraverseSprite);
					break;
				case 3:
					win.Draw(wallGooSprite);
					break;
				}
			}
	}



This is all with in the draw function.

Any ideas why i don't get anything?

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: SMFL sprites and arrays

#2 GetSet  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 68
  • Joined: 08-February 11

Re: SMFL sprites and arrays

Posted 11 March 2012 - 09:23 AM

View PostEnlightenWebDesign, on 10 March 2012 - 09:09 AM, said:

Heres the code i have but it doesn't show any of the different types of walls

This is all with in the draw function.

Any ideas why i don't get anything?

Thanks!


Hi. This isn't your full source (or is it?). No telling where the problem might reside without the full source. But from the looks of it, beyond you having no window/frame/canvas to draw to, if win.draw() is a method in the fashion you are using it, shouldn't you also be passing it some x,y coordinates to indicate where on screen to draw the sprite?

I would have to investigate SFML to see what's what further. Will wait til you post your full source.
Was This Post Helpful? 0
  • +
  • -

#3 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 208
  • View blog
  • Posts: 552
  • Joined: 12-July 09

Re: SMFL sprites and arrays

Posted 12 March 2012 - 02:17 AM

Like GetSet said, you have to set the position of the sprite:
sprite.SetPosition(x * cellWidth, y * cellHeight);

Or swap x and y if your grid is the other way around.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1