Jump to content
  • Advertisement
Sign in to follow this  
Clobslee

Rendering Sprites from LinkedList odd behavior?

This topic is 1153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a small multi-player game and am wondering why only a few of these items are being rendered when I add them to the render list.

 

When I kill a monster the server sends a packet to everyone playing that drops an item at that mobs location. The first time I kill a monster it works as expected, but after that it's random. Usually around the 4th or 5th monster killed another renders correctly. The last time I ran a little test the items that dropped and rendered correctly were the 1st, 6th, and 10th. I have verified that the items are all being added to the list, but not all of them render. I'm assuming it has something to do with the sprite texture being blank but I haven't confirmed this and am lost as to why this would be occurring to some and not others when they are being created the same way.

 

 

Client Code adding to renderer List

if (object instanceof ItemDroppedPack)
			{
				System.out.println("Recieved ItemDroppedPack");
				ItemDroppedPack pack = (ItemDroppedPack) object;
				
				
				System.out.println("Pack itemID = " + pack.itemID);
				if (pack.itemID == 0)
				{
					int attack = pack.roll1 / 10;
					Weapon weaponDropped = new Weapon();
					weaponDropped.set(new Sprite(swordTexture));
					weaponDropped.floorX = pack.x;
					weaponDropped.floorY = pack.y;
					weaponDropped.floorZ = pack.z;
					weaponDropped.setDamage(attack);
					System.out.println("Dropped weapon to floor");
					////mapFloor.add();
					renderer.addItem(weaponDropped);

					System.out.println("Floor count: " + renderer.getFloorItems().size());
					//renderer.getFloorItems().get()
				}
					
			}

Rendering Items

public void render(float stateTime) {
	beginRender();
	int currentLayer = 0;
	for (MapLayer layer : map.getLayers()) {
	    if (layer.isVisible()) {
		if (layer instanceof TiledMapTileLayer) 
		{
	   		renderTileLayer((TiledMapTileLayer)layer);

			//Items
			final Iterator<Item> it = floor.iterator();
			while(it.hasNext()) 
			{
				Item item = it.next();
				
				if (item.getFloorZ() == currentLayer)
				{
					//if (item == null)
						//System.out.println("Item is null");
					this.getBatch().draw(item, item.getFloorX(), item.getFloorY());		
				}
		
			    //do stuff with label
		
			
			}
			//System.out.println("Rendered Items...");
		  	/*for(Item sprite : floor)
			{
				//System.out.println("DRAWING SPRITE");
				if (sprite.getFloorZ() == currentLayer)
					this.getBatch().draw(sprite, sprite.getFloorX(), sprite.getFloorY());			
				//batch.draw(player.getAnimator().getCurrentAnimation().getKeyFrame(stateTime, player.isMoving()),player.getX(), player.getY());

			}	*/

		

		    currentLayer++;
		    if(currentLayer == drawSpritesAfterLayer){

			

                        //Monsters
			final Iterator<Monster> monster = mobList.iterator();
			while(monster.hasNext())
			{
				try
				{
				Monster mob = monster.next();
				this.getBatch().draw(mob.getAnimator().getCurrentAnimation().getKeyFrame(stateTime, mob.shouldAnimate()), mob.getMap_x(), mob.getMap_y());
				}
				catch(Exception e)
				{
					//[attachment=28308:gameHelp.png][attachment=28308:gameHelp.png]System.out.println("Trouble Rendering Monsters, trying again");
					//render(stateTime);
					
				}
				
			}
			//System.out.println("Rendered Mosters");

			//Players
			final Iterator<Player> playerIt = sprites.iterator();
			while(playerIt.hasNext()) 
			{
				Player player = playerIt.next();
				this.getBatch().draw(player.getAnimator().getCurrentAnimation().getKeyFrame(stateTime, player.shouldAnimate()), player.getMap_x() - 64, player.getMap_y() - 64);
			}
			//System.out.println("Render Players");
			
                    }
                } 
            }
        }
        endRender();
    }

Server Log

Instance Created...
Server Running...
Player connecting to server...
New player's ID is: 1
Player connected to server with ID: 1
Sending ItemDroppedPack to all connected players
Sending ItemDroppedPack to all connected players
Sending ItemDroppedPack to all connected players
Sending ItemDroppedPack to all connected players
Sending ItemDroppedPack to all connected players
Sending ItemDroppedPack to all connected players
Sending ItemDroppedPack to all connected players
Sending ItemDroppedPack to all connected players


Client Log

Recieved ItemDroppedPack
Pack itemID = 0
Dropped weapon to floor
Floor count: 1
Sending Spawn Mob
Recieved SpawnMobPack. Doing so...
Found room for new mob
Sending Spawn Mob
Buff has expired...
Buff has expired...
Buff has expired...
Buff has expired...
1
1
1
1
1
1
1
1
Mob clicked...
Recieved ItemDroppedPack
Pack itemID = 0
Dropped weapon to floor
Floor count: 2
Sending Spawn Mob
Recieved SpawnMobPack. Doing so...
Found room for new mob
Sending Spawn Mob
Sending Spawn Mob
Recieved ItemDroppedPack
Pack itemID = 0
Dropped weapon to floor
Floor count: 3
Sending Spawn Mob
Recieved SpawnMobPack. Doing so...
Found room for new mob
Sending Spawn Mob
Sending Spawn Mob
Sending Spawn Mob
Sending Spawn Mob
Recieved ItemDroppedPack
Pack itemID = 0
Dropped weapon to floor
Floor count: 4
Sending Spawn Mob
Recieved SpawnMobPack. Doing so...
Found room for new mob
Sending Spawn Mob
Sending Spawn Mob
Sending Spawn Mob
Recieved ItemDroppedPack
Pack itemID = 0
Dropped weapon to floor
Floor count: 5
Buff has expired...
Sending Spawn Mob
Recieved SpawnMobPack. Doing so...
Found room for new mob
Sending Spawn Mob
Sending Spawn Mob
Sending Spawn Mob
Recieved ItemDroppedPack
Pack itemID = 0
Dropped weapon to floor
Floor count: 6
Sending Spawn Mob
Recieved SpawnMobPack. Doing so...
Found room for new mob
Sending Spawn Mob
Sending Spawn Mob
Sending Spawn Mob
Sending Spawn Mob
Recieved ItemDroppedPack
Pack itemID = 0
Dropped weapon to floor
Floor count: 7
Sending Spawn Mob
Recieved SpawnMobPack. Doing so...
Found room for new mob
Sending Spawn Mob
Sending Spawn Mob
Sending Spawn Mob
Recieved ItemDroppedPack
Pack itemID = 0
Dropped weapon to floor
Floor count: 8

BUILD SUCCESSFUL

Total time: 5 mins 27.969 secs


Showing the floor after I've killed 8 mobs, the floor list has 8 items, but only 3 render.

[attachment=28308:gameHelp.png]

Edited by Clobslee

Share this post


Link to post
Share on other sites
Advertisement

I was completely wrong. After a bit of play I gave up and decided to just add a few more swords and roll for which one is dropped. When some new textures were rendered I realized that the swords were all rendering, they were just rendering on top of each other! (Aka the x and y are off and I'm pretty sure I know why).

 

Almost a bit humorous so I figured I'd share.

Edited by Clobslee

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!