Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (762)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (847)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Populating sprites in a platformer  (Read 3243 times)
0 Members and 1 Guest are viewing this topic.
Offline zparticle

Senior Devvie

Thick As A Brick

« Posted 2002-12-22 18:42:10 »

It is starting to look like the game I'm working on will have massive level maps with a boat load of enemy and pick-up and power-up sprites. My question is this:

I'll place the sprites initially based on clues from the level map data. I could prepopulate the entire level or only populate those areas that have been uncovered by the player. Which would you do?

My concern is that with an enormous number of sprites to update positions on each frame it could slow down the game. On the other hand I could just prepopulate everything and only update the visible ones.

Offline Harley Rana

Junior Devvie

Java games rock!

« Reply #1 - Posted 2002-12-23 03:36:45 »

Id guess that updating the visible sprites is the best way to go.
checking if the sprite is visible should be pretty easy.
mabye if the sprites are sorted by in the array, then you could have the min and max visible indexes.
Offline princec

« JGO Spiffy Duke »

Medals: 1038
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #2 - Posted 2002-12-23 10:06:21 »

I'd suggest having a zone around the visible area in which sprites are activated and kept animated, as you could walk off a moment and walk back and the gidrahs would mysteriously disappear...

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Contrast

Junior Newbie

where's the beef?

« Reply #3 - Posted 2002-12-23 17:16:44 »

i think it's a question of what you want the game to behave like. in order from least to most processor work:

1, like princec suggested, you can have cues inside your level to create an enemy when the screen's border touches this or that location. the result is like mega man: the enemies will vanish and die when they leave the screen, or they can mysteriously reappear when you run back toward where you killed them before.

2, like harley suggested, you can create all the enemies and only update them when they're onscreen. the result is that if you outrun an enemy that's chasing you, he won't keep chasing you once he's outside the screen, yet if you step back he'll be right there as though nothing had happened.

to make the cons of the above two methods less problematic, you can use a shape focused around your character that is larger than the screen. basically this allows the enemies to drift off the screen a little ways and then come back on. i think double dragon did this.
you could also try keeping enemies awake for a limited time after they had left the screen, and then ceasing updates if the time elapsed before they returned. in a game like sonic the hedgehog, where the character can travel many screens in a second, this method is faulty.

3, you can keep a list of all the enemies that have been on the screen, and update those. as such, once an enemy is 'awake', he's awake for good, but he won't wake up until your character gets close.

4, you can work your AI as a state machine, and have all or most of your enemies start out in their 'idle' state. idle in this case would mean doing squat, such that updating them would execute practically no code. then, when the player saw them, the enemy would wake up (change to an aggressive state). you might want the idle state to even do a quick line-of-sight scan for the player, such that enemies a few screens off might see him, wake up, and come running.

the above two methods become worse and worse ideas as you increase the number of enemies in your level, but i've used this method and had a few hundred objects being updated with simple physics (maybe 20 lines of java executed for each) plus several with in-depth physics, and seen no slowdown at all.
Offline zparticle

Senior Devvie

Thick As A Brick

« Reply #4 - Posted 2002-12-23 22:52:56 »

Thanks everyone for your input, I think I'll do a combination of the solutions presented here.

1> Prepopulate everything.

2> Take the power-ups and pick-ups and only update them while they are on screen, since they stay stationary but have animations.

3> Take the enemies that travel various paths inside of the levels and always update their positions but only update their animations while they are on screen.

Now I just have to come up with an efficient method to determine what to update based on the rules above.

Offline Harley Rana

Junior Devvie

Java games rock!

« Reply #5 - Posted 2002-12-24 20:32:20 »

Hey id like to also suggest using 2 different lists, 1 for the activated sprites, and 1 not activated.

I don't know how you have you levels, but assuming each is like a big rectangle.   You could easily sort the enemys in the non activated list by there X position.
You would still need to check if the enemy was visible, but not have as many checks.

When the enemy is visible put it into the activated list until it dies.  Then you update every sprite in the active list, with each sprites AI finding the right action.  If the enemys can get the players postion, you could make the enemy sleep if the distance is large enough.  Mabye then kill the enemy is the distance is huge.

Hope that helps Smiley
Pages: [1]
  ignore  |  Print  

EgonOlsen (367 views)
2018-06-10 19:43:48

EgonOlsen (374 views)
2018-06-10 19:43:44

EgonOlsen (305 views)
2018-06-10 19:43:20

DesertCoockie (549 views)
2018-05-13 18:23:11

nelsongames (874 views)
2018-04-24 18:15:36

nelsongames (857 views)
2018-04-24 18:14:32

ivj94 (1317 views)
2018-03-24 14:47:39

ivj94 (428 views)
2018-03-24 14:46:31

ivj94 (1100 views)
2018-03-24 14:43:53

Solater (448 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!