Vector arrays? ( luigi is a square lolz )

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Vector arrays? ( luigi is a square lolz )

Post by N64vSNES »

So been working on the basic backbone of the NPC system for the eternal quest.

I'm using a vector array since static would be plain stupid but when I staticly add a NPC from a file everything works

-Coordinance gets set
-Spritesheet successfully loads
etc...

Everything is correctly loaded but luigi seems to be a square.......

Image

I'm probably overlooking a very simple problem but I'm quite stuck :|

Here is my NpcManager.h

Code: Select all

#ifndef NPC_MANAGER_H
#define NPC_MANAGER_H

#include "NPCs.h"

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

namespace Eternal {

	class NpcManager {

	private:

			NpcManager();
			static NpcManager *MyManager;

		public:

			static NpcManager *GetManager();
			~NpcManager();

			int AddNpc(float x, float y, std::string file);
			void RemoveNpc(int npc);

			void UpdateManager();

		private:

			int Top;
			std::vector <Eternal::NPC> Npcs;

	};

}

#endif
And my .cpp

Code: Select all

#include "NPCManager.h"

#include "Primitives.h"
#include "DebugLog.h"
#include "Camera.h"

using namespace Eternal;

NpcManager *NpcManager::MyManager = 0;

NpcManager *NpcManager::GetManager() {
	if ( MyManager == 0 ) {
		MyManager = new NpcManager;
	}
	return MyManager;
}

NpcManager::NpcManager() {
	Top = 0;
}

NpcManager::~NpcManager() {

}

int NpcManager::AddNpc(float x, float y, std::string file) {

	std::ifstream ifile;

	NPC npc;

	ifile.open( file.c_str() );

		std::string texture;
		ifile >> texture;
		ifile >> npc.Name;
		ifile >> npc.SpriteSheet.Crop.w;
		ifile >> npc.SpriteSheet.Crop.h;

	ifile.close();

	npc.SpriteSheet.Load(texture.c_str()); // .......
	npc.SpriteSheet.Pos.x = x;
	npc.SpriteSheet.Pos.y = y;	
	npc.SpriteSheet.Pos.w = npc.SpriteSheet.Crop.h;
	npc.SpriteSheet.Pos.w = npc.SpriteSheet.Crop.h;
	npc.SpriteSheet.SetColor(255,255,255); // openGL ( original texture colors )

	Npcs.push_back(npc);

	Top++;

	return Top - 1;
}

void NpcManager::RemoveNpc(int npc) {
	Npcs.erase(Npcs.begin() + npc);	
Top--;
}

void NpcManager::UpdateManager() {
	Camera *CameraSys = Camera::GetInstance();
	for ( int i = 0;i < Top;i++ ) {
		CameraSys->RenderSprite( Npcs[i].SpriteSheet );
	}
}
Sorry for the lack of comments.

If this helps any here is the NPCs file content I allocated it from

Code: Select all

Data/mario.png --SpriteSheet
Luigi --Name
32 -- Width
64 -- Height
1 -- Nothing past this point is getting loaded so I won't go into details
1
1
Data/Scripts/TestScript1.lua
~c999Hello, I've been staticly allocated from a file.
I bet this is a really simple fix but anyone?
User avatar
k1net1k
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 563
Joined: Sun Nov 07, 2010 2:58 pm
Contact:

Re: Vector arrays? ( luigi is a square lolz )

Post by k1net1k »

i dont know about the code, but i assume its nothing to do with the actual spritesheet ? eg luigi doesnt exist on it ?
gm3dgames
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 5
Joined: Thu Nov 11, 2010 11:33 pm
Current Project: GM3D 2D Game Engine
Favorite Gaming Platforms: PC, Dreamcast, Xbox360
Programming Language of Choice: C++

Re: Vector arrays? ( luigi is a square lolz )

Post by gm3dgames »

im wondering if this:

Code: Select all

   
npc.SpriteSheet.Pos.w = npc.SpriteSheet.Crop.h;
npc.SpriteSheet.Pos.w = npc.SpriteSheet.Crop.h;
(located in you .cpp) has anything to do with it, unless this is intentional, the crop is going to set the width to the height of the crop.
and its there twice without the setup of the height.

should it be this?

Code: Select all

   
npc.SpriteSheet.Pos.w = npc.SpriteSheet.Crop.w;
npc.SpriteSheet.Pos.h = npc.SpriteSheet.Crop.h;
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Vector arrays? ( luigi is a square lolz )

Post by N64vSNES »

k1net1k wrote:i dont know about the code, but i assume its nothing to do with the actual spritesheet ? eg luigi doesnt exist on it ?
Nope debug log confirms its been loaded correctly and when I don't set the Pos.w and Pos.h the rectangle is default 128x128 which is the same dimensions are luigi's spritesheet so its loading correctly :(

gm3dgames wrote:im wondering if this:

Code: Select all

   
npc.SpriteSheet.Pos.w = npc.SpriteSheet.Crop.h;
npc.SpriteSheet.Pos.w = npc.SpriteSheet.Crop.h;
(located in you .cpp) has anything to do with it, unless this is intentional, the crop is going to set the width to the height of the crop.
and its there twice without the setup of the height.

should it be this?

Code: Select all

   
npc.SpriteSheet.Pos.w = npc.SpriteSheet.Crop.w;
npc.SpriteSheet.Pos.h = npc.SpriteSheet.Crop.h;
Yeah my bad, I corrected this mistake just after I posted this, but this dosen't solve the problem :(
Sour-Lemon
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 1
Joined: Fri Oct 22, 2010 6:20 am

Re: Vector arrays? ( luigi is a square lolz )

Post by Sour-Lemon »

I'm not sure that I can help you, but I was wondering, what is the SetColor(); function doing?

It's just that, Luigi is appearing as a white block, and the last thing you are doing before you call Npcs.push_back() in NpcManager::AddNpc() is:
npc.SpriteSheet.SetColor(255,255,255);

Is it just setting a colour to use for transparency?

Also is Mario being loaded using the same functions?
If he is being loaded seperately for whatever reason are there any differences in the code that is doing it?
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Vector arrays? ( luigi is a square lolz )

Post by N64vSNES »

Sour-Lemon wrote:I'm not sure that I can help you, but I was wondering, what is the SetColor(); function doing?

It's just that, Luigi is appearing as a white block, and the last thing you are doing before you call Npcs.push_back() in NpcManager::AddNpc() is:
npc.SpriteSheet.SetColor(255,255,255);

Is it just setting a colour to use for transparency?

Also is Mario being loaded using the same functions?
If he is being loaded seperately for whatever reason are there any differences in the code that is doing it?
Set color isn't really nessacary as the Image() constructor sets that by default but I thought this may fix this but no

the 255,255,255 is because I'm using openGL and when I call render it calls glColor3f( r / 255, g / 255, b / 255 ); if you don't know much about openGL this basicly just leaves the colors as they should be.

Thanks.
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Vector arrays? ( luigi is a square lolz )

Post by Bakkon »

Check to make sure the texture you're binding for Luigi is created properly. That looks pretty similar to when you try to draw with an invalid texture.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Vector arrays? ( luigi is a square lolz )

Post by N64vSNES »

Bakkon wrote:Check to make sure the texture you're binding for Luigi is created properly. That looks pretty similar to when you try to draw with an invalid texture.
I've checked through the rendering and I can defnitly say that the is no issue with the texture as I've tried switching textures with the player and thats working fine.

EDIT:

Also I should point out for rendering the is two methods

1 ) Image class
2 ) SpriteSheet class

But this is irrelevant since tiles, party members and npc's are all using the Image class

EDIT:
Still open for suggestions? :(
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Vector arrays? ( luigi is a square lolz )

Post by N64vSNES »

Okay dudes I found the problem ( Thanks to WSP_SNIPER )

I think because its actully a dynamic array you have to pass a pointer when you push a element onto the array.

Thanks.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Vector arrays? ( luigi is a square lolz )

Post by Falco Girgis »

N64vSNES wrote:Okay dudes I found the problem ( Thanks to WSP_SNIPER )

I think because its actully a dynamic array you have to pass a pointer when you push a element onto the array.

Thanks.
Nope. That's not true. If that were the case it wouldn't even have compiled at all to begin with when you tried to push an NPC back into an NPC * vector.

So did you change

Code: Select all

         std::vector <Eternal::NPC> Npcs;
To

Code: Select all

std::vector <Eternal::NPC *> Npcs
and begin pushing back pointers to dynamically allocated NPCs?

If that's the case (and now works), your copy constructor must be fucked.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Vector arrays? ( luigi is a square lolz )

Post by dandymcgee »

GyroVorbis wrote:If that's the case (and now works), your copy constructor must be fucked.
And assignment operator. :|
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Vector arrays? ( luigi is a square lolz )

Post by Falco Girgis »

Not to sound like a prick either, but why do you compare your pointers to 0 rather than NULL? I think that's annoying as hell and makes it unclear that the comparison is between a pointer and a memory address rather than an integer variable and a constant... :)
User avatar
Khearts
ES Beta Backer
ES Beta Backer
Posts: 50
Joined: Sun Oct 10, 2010 5:07 pm
Current Project: Super Mario Bros Clone and 3D Engine
Favorite Gaming Platforms: Dreamcast
Programming Language of Choice: C/++

Re: Vector arrays? ( luigi is a square lolz )

Post by Khearts »

I thought NULL == 0...?
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Vector arrays? ( luigi is a square lolz )

Post by Falco Girgis »

Khearts wrote:I thought NULL == 0...?
It does. That's not the point, though.

If comparing a pointer to 0 were a good practice, why the hell would the keyword/macro NULL even exist? It's not a good practice.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Vector arrays? ( luigi is a square lolz )

Post by N64vSNES »

GyroVorbis wrote:
Khearts wrote:I thought NULL == 0...?
It does. That's not the point, though.

If comparing a pointer to 0 were a good practice, why the hell would the keyword/macro NULL even exist? It's not a good practice.
I didn't think that assigning pointers to 0 was that big of a deal since the NULL marco is defined as 0 to begin with.
I suppose its better for readability so I'll start using NULL.


And yes I changed it from
std::Vector <Eternal::Npc> Npcs;
to
std::Vector <Eternal::Npc> Npcs;

Then dynamicly allocate a NPC and pass that onto the array and deallocate it when the NPC gets removed, this wasn't the issue?
Post Reply