Jump to content
  • Advertisement

Affected1

Member
  • Content Count

    21
  • Joined

  • Last visited

Community Reputation

128 Neutral

About Affected1

  • Rank
    Member
  1. Affected1

    Draw all items from std::map

    I managed to make one object of ItemManager global now but after working on the character class a little i get this error during compile: Character.obj : error LNK2001: unresolved external symbol "class ItemManager itm_mgr" (?itm_mgr@@3VItemManager@@A) I have extern "ItemManager itm_mgr" in character.h and "ItemManager* itm_mgr = new ItemManager()" in dgame.cpp. dgame.h includes character.h so i dont understand why it cant find it.
  2. Affected1

    Draw all items from std::map

    How can i make only one ItemManager object and then make it global so every class can access it? I tried using extern in the stdafx.h but that dint end well..
  3. Affected1

    Draw all items from std::map

    I managed to make a working character class but couldn't figure out how to store the items for each character. Here is the class: #ifndef _H_CHARACTER #define _H_CHARACTER #include "stdafx.h" #include "ItemManager.h" class Character { public: Character(std::string bodyName, int x, int y); void Draw(sf::RenderWindow* rw); void SetPosition(int x, int y); private: void DrawItems(sf::RenderWindow* rw); ItemManager itm_mgr; Item body; int posX; int posY; }; #endif - #include "Character.h" Character::Character(std::string bodyName, int x, int y) {     body = itm_mgr.LoadItem(ITYPE_BODY, bodyName);     posX = x;     posY = y; } void Character::Draw(sf::RenderWindow* rw) {     body.itemSprite.setPosition(posX, posY);     rw->draw(body.itemSprite); } void Character::DrawItems(sf::RenderWindow* rw) { } void Character::SetPosition(int x, int y){posX = x; posY = y;} I tried using std::map for the items but that dint work.
  4. Affected1

    Draw all items from std::map

    Thanks guys, it works now but i realized that if i have multiple player characters and one character is made up of multiple items, then i dont have a way to manage all the characters and move them individually on the screen. What should i do?
  5. I have many items in a std::map and i need to draw them all using SFML. So far i have the following in a class called ItemManager which stores all items: std::map<std::string, Item> items_; "Item" is defined here: struct Item { const char* name; ItemType type; sf::Sprite itemSprite; int x, y, sizeX, sizeY; int posX, posY; int offsetX, offsetY; }; Now i need to send the std::map that contains all items to the main class called DGame and draw them there but i dont know how to send them there as i dont have much experience with std::map.
  6. Affected1

    Multiple items in XML

    A while loop works perfect with it! Thanks  
  7. Affected1

    Multiple items in XML

    Using NextSiblingElement() did the trick, thanks . Is there a way to count how many items there are in the main <data> node so i could use an for loop to print all of them? Or do i need to make another node for that like <itemcount> and then update that everytime i add a new item to the XML?
  8. I'm making a small project as a learning experience with XML parsing.   I have the following XML file: <data> <item> <type>User</type> <name>TestUser1</name> <permission>Admin</permission> </item> <item> <type>User</type> <name>TestUser2</name> <permission>Normal</permission> </item> </data> and the following code to parse the XML: XMLDocument doc; doc.LoadFile("data.xml"); XMLElement* dataNode = doc.FirstChildElement("data"); XMLElement* itemNode = dataNode->FirstChildElement("item"); const char* type = itemNode->FirstChildElement("type")->GetText(); const char* name = itemNode->FirstChildElement("name")->GetText(); const char* permission = itemNode->FirstChildElement("permission")->GetText(); printf("--- ITEM ---"); printf("Type: %s\n", type); printf("Name: %s\n", name); printf("Permissions: %s\n", permission); This works well for one item but how could i iterate through the whole XML and print out every item and their properties? I'm fairly new to XML so this might be something very simple that i just overlooked. Thanks in advance.
  9. Affected1

    Converting Android game to PC

    That seemed to help with scaling because now all the smaller textures seem to be correctly scaled but the background and other bigger textures are too big now. I will test with some code to check if the texture is bigger or smaller than the screen size and then use different scaling code according to that.   EDIT: Now they all seem to be scaled correctly but some textures aren't drawn where they are supposed to or they might still have wrong scaling. I will look into that and edit here if i cant figure it out.
  10. Affected1

    Converting Android game to PC

    I tried getLocalBounds too and it dint make any difference.
  11. Affected1

    Converting Android game to PC

    So i changed the code to this: float f1 = dst.width/sprite.getGlobalBounds().width; float f2 = dst.height/sprite.getGlobalBounds().height; sprite.setScale(f1, f2); but now the sprite is drawn very small. Here is the code in debug mode when it draws a texture with dimensions of 55x55: //In game's render loop code f11 = (55.0F / scaleValues) * bitmapscale; //scaleValues = 1.0000000 and bitmapscale = 0.68571430 RectF rectf5; rectf5.x = 0.0F; rectf5.y = 0.0F; rectf5.width = f11; // f11 = 37.714287 rectf5.height = f11; sprite.setTexture(arm); //Size of 'arm' texture is 55x55 c->Draw(sprite, NULL, rectf5, "arm"); //------------------------------------------------------------- //In Canvas::Draw float f1 = dst.width/sprite.getGlobalBounds().width; // f1 = 0.053877551 float f2 = dst.height/sprite.getGlobalBounds().height; // f2 = 0.039532796 sprite.setScale(f1, f2); // scaling goes wrong here for some reason sprite.setPosition(cx, cy); sprite.setRotation(crotation); canvasTexture.draw(sprite); canvasTexture.draw(text); Now with the new division code the background texture gets bigger than the screen so a part of it cant be seen.
  12. Affected1

    Converting Android game to PC

    By "below zero" you mean negative values? A scale by a negative value will mirror the image, for the image to shrink you need a scale value between 0 and positive 1 (0 will make it disappear, 1 doesn't change it). Can you post the values from the divisions here?   Oh damn, i wrote that in a hurry so i dint really think it through. What i meant was that the values were between 0 and 1. 0.6857142857142857 is the result of SCREENW/dst.width and 0.6708595387840671 is the result of SCREENH/dst.height when scaling the background. Invalid results were way above 1. Like 6 and even 24.
  13. Affected1

    Converting Android game to PC

    'src' is never used in the original android code either so its just there to better mimic the android canvas's drawBitmap syntax. I might remove it later when everything is working properly. Here is an example of how the background is drawn: void App::DrawBackground(Canvas *c) { c->save(); c->clear(); //Fill canvas with magenta color RectF rect; rect.x = 0.0F; rect.y = 0.0F; rect.width = backgroundSprite.getGlobalBounds().width; rect.height = backgroundSprite.getGlobalBounds().height; imgOffsetX = SCREENW / 2.0F - nImageWidth / 2.0F; imgOffsetY = screenHalfHeight - nImageHeight / 2.0F; c->translate(imgOffsetX, imgOffsetY); c->Draw(backgroundSprite, NULL, rect); //'sprite' that is used here is global for the whole App class and is used everywhere in the game code but with one texture at a time sprite.setTexture(character); c->Draw(sprite, NULL, rect); c->restore(); } The SCREENW/dst.width division was just a guess because i wasnt sure how android does it and because it worked with the background texture i thought it would work with other textures too but it didn't.   I inspected the results of divisions with breakpoints in Visual Studio by placing a breakpoint at the line after the division and then checking the values from 'sprite' object. I will setup some code to output the results to console instead so checking them will be easier.   EDIT: After setting up some code and checking the division results from console, i noticed that the division results for background texture are below zero and for other textures they were well above zero. And from what i understand, it must be below zero everytime so then it would scale the textures smaller and not bigger when using sprite.setScale.
  14. Affected1

    Converting Android game to PC

    dst.width and dst.height are floats as RectF is rectangle class with all values as floats like in android RectF. I changed the scale code to: sprite.setScale((float)SCREENW/dst.width, (float)SCREENH/dst.height); but it still wrongly scales them too big. I'm thinking the problem is that this division is not how android does the scaling to fit the bitmap in the rectangle. I tried looking around in the android source code but its just too complex to find anything so specific.
  15. Affected1

    Converting Android game to PC

    So i'm pretty sure the restore and save functions are working now. But i got a new problem with the canvas class: when i draw a bitmap, i need to scale it to fit in a rectangle. Here is my code so far: void Canvas::Draw(sf::Sprite sprite, Rect *src, RectF dst) { sprite.setScale(SCREENW/dst.width, SCREENH/dst.height); sprite.setPosition(cx, cy); sprite.setRotation(crotation); canvasTexture.draw(sprite); } It works for some bitmaps but with smaller ones it scales them way too big. The background image is 700x954 and that works fine but some other bitmap is 141x126 and it scales that way up when it should scale them down to fit the 'dst' rectangle. Any advice on this?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!