Jump to content


Photo

Minecraft game lag problem


  • Please log in to reply
11 replies to this topic

#1 seanrr

seanrr

    GMC Member

  • GMC Member
  • 25 posts

Posted 17 August 2012 - 08:18 PM

Im trying to make a game like a 2D minecraft and the only problem is that its running really slow. It runs at about 9 fps i would like it to run at about 30 fps. I have all the blocks that are not shown on screen not drawn which helps it a lot but still runs slow since theres 4805 blocks in the room. Is there any ways of making the game run faster without making the room smaller or making the blocks bigger?
  • 0

#2 FAAAEBS

FAAAEBS

    GMC Member

  • GMC Member
  • 157 posts
  • Version:GM8

Posted 17 August 2012 - 08:26 PM

What is the game window's dimension?
  • 0

#3 seanrr

seanrr

    GMC Member

  • GMC Member
  • 25 posts

Posted 17 August 2012 - 08:31 PM

What is the game window's dimension?

The game windows dimensions are 480x320.
  • 0

#4 Debels

Debels

    GMC Member

  • GMC Member
  • 1997 posts
  • Version:GM:Studio

Posted 17 August 2012 - 08:32 PM

Im trying to make a game like a 2D minecraft and the only problem is that its running really slow. It runs at about 9 fps i would like it to run at about 30 fps. I have all the blocks that are not shown on screen not drawn which helps it a lot but still runs slow since theres 4805 blocks in the room. Is there any ways of making the game run faster without making the room smaller or making the blocks bigger?

Try deactivating all the instances that aren't shown on the screen

BTW: What GM version are you using?

Edited by Debels, 17 August 2012 - 08:32 PM.

  • 0

#5 seanrr

seanrr

    GMC Member

  • GMC Member
  • 25 posts

Posted 17 August 2012 - 08:38 PM

BTW: What GM version are you using?


Im using version 7 for mac. Ill try what you said.
  • 0

#6 seanrr

seanrr

    GMC Member

  • GMC Member
  • 25 posts

Posted 17 August 2012 - 08:57 PM

Thanks deactivating the instances helped.
  • 0

#7 The Legend

The Legend

    A Jesus Freak

  • GMC Member
  • 1052 posts
  • Version:GM:Studio

Posted 17 August 2012 - 08:59 PM

In addition to deactivating the instances, try also making them invisible when they are off screen. I tried something like this awhile ago too and it helps if the program doesn't need to display so many sprites.
  • 0

#8 Dylan93

Dylan93

    GMC Member

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 18 August 2012 - 09:49 AM

In addition to deactivating the instances, try also making them invisible when they are off screen. I tried something like this awhile ago too and it helps if the program doesn't need to display so many sprites.


When the instance is deactivated they are already invisible...

When you deactivate instances they are in some sense removed from the game. They are not visible anymore nor are any events executed for them.


  • 0

#9 Madales

Madales

    GMC Member

  • GMC Member
  • 62 posts
  • Version:GM8

Posted 18 August 2012 - 10:54 AM

When you deactivate instances they are in some sense removed from the game. They are not visible anymore nor are any events executed for them.


This is true! The fact is that if there are too many static objects inside a room, this is slowed. The best solution is therefore to deactivate objects that are located in the region of the room out of view, then:
instance_deactivate_region(view_xview[0],view_yview[0],view_xview[0]+view_wview[0],view_yview[0]+view_hview[0],false,true)
But the objects, while being deactivated, aren't destroyed. In fact, they may be reactivated with the opposite function, namely:
instance_activate_region(view_xview[0],view_yview[0],view_xview[0]+view_wview[0],view_yview[0]+view_hview[0],true)

- Madales

Edited by Madales, 18 August 2012 - 10:56 AM.

  • 0

#10 Docopoper

Docopoper

    You are observant!

  • GMC Member
  • 1287 posts
  • Version:GM:Studio

Posted 30 August 2012 - 02:55 PM

1) Make sure you have a ds_grid containing the id of every block - as because they are grid aligned, this will make checking neighbouring blocks much much faster than traditional methods.

2) Only update blocks in an update event (such as user_event 0). If a block changes - update its neighbours there is no need to constantly check surrounding blocks for things like water.

3) Using a ds_grid should make choosing what blocks to draw a much faster process.

Given these rules - I have successfully created a 2D Minecraft clone with dynamic lighting and fluid dynamics. However - I lost the file when I upgraded computer... so I can't post it. :/

But still - these are a necessity for creating 2D Minecraft clones.
  • 0

#11 falconfetus8

falconfetus8

    GMC Member

  • GMC Member
  • 38 posts
  • Version:Unknown

Posted 30 August 2012 - 04:24 PM

If I were you, I wouldn't use objects as blocks. The deactivation solution won't work because any mobs that are offscreen will fall through the deactivated blocks and die. What you should do instead is use a ds_grid, as the person above me said. Instead of using the collision event, use a collision_rectangle inside of a for loop.
  • 0

#12 Docopoper

Docopoper

    You are observant!

  • GMC Member
  • 1287 posts
  • Version:GM:Studio

Posted 30 August 2012 - 05:13 PM

No need to use collision_rectangle if you have everything aligned to a grid. You can simply check if a cell contains a solid object directly.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users