Yo!
I've got this side scroller I'm working on and need some insight on how one would make items appear onscreen at certain points.
One Idea I had was to make a clock using the value from millisec to get the time value when you start the game and comparing it to the current value from millisec at some point in-game.
Then I would have them appear on screen depending on the current time spent in-game.
I think that'd work but I feel like there are better ways of going at it.
Thanks!
Items in a side scroller?
Root / Programming Questions / [.]
CosmicTacoCatCreated:
MILLISEC is not so good for determining in-game time: for one thing, the HOME button is sometimes used as a 'pause' button, and that time is counted in MILLISEC.
I would use a counter in your main game loop. You could even tweak the timer so that, for example, if the player moves or fights, your clock ticks faster, so if they're just sitting there, it takes longer to appear.
hmm good to know.
So for a counter I could just increment the value some counter variable by 1 each frame, ye?
Sounds like it'd keep things synced even with lag too!
You should implement an event queue to handle asynchronic events. This page explains the concept.
http://gameprogrammingpatterns.com/event-queue.html
Here is a topic where I asked about this before ( http://smilebasicsource.com/forum?ftid=1275 ), but the implementation is done in lowerdash and I haven't updated the post with my new code.
If you want to check the code on smilebasic then download SmileIDE and open the file __Events. This module:
- Keeps a counter that increase based on the game loop.
- Let you schedule a function that receive a String. This string act as a bundle that contains multiples variables. Also, the module let you assign a tag to the event.
- Has functions to encode any kind of variable(String, number, String array, number array) in a string. That string works similar to Data functions of smilebasic in the way that the data is encoded and decoded on a queue.
- Let you remove events by a tag. This is useful if you don't want to trigger an event (For example, if an entity dies).
If you're interested on using that code, then I can post examples about the usage of it.
You should implement an event queue to handle asynchronic events. This page explains the concept. http://gameprogrammingpatterns.com/event-queue.html Here is a topic where I asked about this before ( http://smilebasicsource.com/forum?ftid=1275 ), but the implementation is done in lowerdash and I haven't updated the post with my new code. If you want to check the code on smilebasic then download SmileIDE and open the file __Events. This module: - Keeps a counter that increase based on the game loop. - Let you schedule a function that receive a String. This string act as a bundle that contains multiples variables. Also, the module let you assign a tag to the event. - Has functions to encode any kind of variable(String, number, String array, number array) in a string. That string works similar to Data functions of smilebasic in the way that the data is encoded and decoded on a queue. - Let you remove events by a tag. This is useful if you don't want to trigger an event (For example, if an entity dies). If you're interested on using that code, then I can post examples about the usage of it.Sounds interesting. I suppose if it means advancing my smilebasic education then sure. I'll probably look into it after the programming contest since I've procrastinated pretty hard so far.
MILLISEC is not so good for determining in-game time: for one thing, the HOME button is sometimes used as a 'pause' button, and that time is counted in MILLISEC. I would use a counter in your main game loop. You could even tweak the timer so that, for example, if the player moves or fights, your clock ticks faster, so if they're just sitting there, it takes longer to appear.This is a very good distinction. "Game time" and "real time" aren't necessarily the same thing. Sometimes you need one, other times the other, sometimes both.