PureBasic Forum

speed of sprite animation to the screen
Page 1 of 1

Author:  dan yalte [ Wed Apr 17, 2019 12:48 am ]
Post subject:  speed of sprite animation to the screen

I have been working on a Blackjack game for a while now at this point i am playing around with where I want things on the screen and playing with card sprites and came across an issue or two.

I load a background sprint and display it all good. I then load a card set all sprites and can place them anywhere all good problem #1 if a move the sprite on screen all is good but seems rather slow moving one pixel at a time, seems like that's a lot of drawing. I know to keep the loop being used small and the cards are the same size as what you see in windows about 90 pixels wide if memory is correct. my screen size is 800X600. coded first for linux

I know there are a few options with the refresh rate.not tried And other possibility's(if you know any i have not tried please fill me in ok thanks. would like to try and keep the animation smooth as possible. does not have to be super fast just enough that i don't have to wait too long.

Would not rather post code at this point do to size of all the files needed. I know enough about logic flow and programming to keep things as simple as possible.will if i have too ok let me know.

There will be a simulation mode but the graphics will be turned off for that. deal millions of hands. Used to figure out true odds. and other things.

when i am Done i will post a free version here as a thanks too all. I will have a paid version as well but the free version will be a full version just a few small stat's the free version will not track. otherwise 100% usable no nag ware.

The free version will be such that if you feel no need to pay or are poor you will still be able to learn and use the free version to full extent. 96% the same.

The linux version will be very cheap want to promote linux. windows and mac will be more but no ware near what many sites want for crappy programs.

Thanks for your time people.....

Author:  kurzer [ Wed Apr 17, 2019 9:09 am ]
Post subject:  Re: speed of sprite animation to the screen

I don't know if I completely understand the problem (unfortunately you didn't add a little source code to show the problem), but maybe the animation of the sprites is slow, because your animation loop is synchronized with the VSync of your computers graphics card.

If you are using a LCD or TFT monitor, the refresh rate will probably be 60 Hz, so your animation loop would run 60 times per second. If you move the sprites one pixel at a time in each loop round, you will get a speed of 60 pixels per second.

This means that you have to increase your step size when animating the sprites in order to achieve a higher speed. So instead of one pixel you have to move the sprites for two, three or more pixels per loop pass.

Author:  Saboteur [ Wed Apr 17, 2019 10:12 am ]
Post subject:  Re: speed of sprite animation to the screen

Can you post a little code to show only the loop? There is no necessary to include the sprites, it can be colored squares.
If we see a code which produce that problem it's easy to fix.

Author:  dan yalte [ Wed Apr 17, 2019 2:52 pm ]
Post subject:  Re: speed of sprite animation to the screen

If mc>291
md=md+1: DisplaySprite(1,482+md,15+mc):mc=291
ElseIf DisplaySprite(1,482,15+mc)
If 482+md>690
If md=690
Goto screenflip

in this Example ElseIf DisplaySprite(1,482,15+mc) does most of the work sending the sprite
to bottom of the screen then md=md+1: DisplaySprite(1,482+md,15+mc):mc=291 sends it to the right tell it hits it final spot DisplaySprite(1,691,307) if you don't put the test in for DisplaySprite(1,482+md,15+mc):md=690 the sprite disappears when you get to it's last position. had this been faster. then next cards final position would have been 686,292 five pixels
over from the last card and 15 pixels higher to stack the cards.

This is an example of the kind of loop being used.i am just experimenting at this point to figure out how it all works. After reading both replay’s here i agree it's moving about 60 pixels a second.makes perfect sense, The cards are about 90 pixels wide. So the step rate is most likely the key not all is lost however because i can draw a card coming out of the card shoe then draw the card again in it's final place then blank out the space the first image took up. Drawing this way will be much faster. Not exactly what i was after might try messing with the refresh rate.
but in the end will not likely use that unless i am sure it will work right for all.

Author:  Saboteur [ Wed Apr 17, 2019 4:33 pm ]
Post subject:  Re: speed of sprite animation to the screen

That way there are some things that change the velocity of the cards, frame rate, pixel steps, etc... You need to fix the frame rate to get same speed in all computers, if don't do this, somebody with a default monitor frame rate of 100, will see the game too fast.
With the frame rate, you will hace to adjust the pixel steps of the cards. I added a basic example of acceleration to see how works.

The best way would be to calculate time between frames and add the steps you need to get the best animation. I think there are many tutorials in internet about that to see here.



SetFrameRate(60)        ; <---- changing this to 30 or 15, change velocity


acceleration.f=0.1      ; <----- change acceleration to 0.2 to change speed

  If (acceleration>10)
  mc=mc+acceleration       ;  <----- changing this to a fix value: 1, 2, 5, 10..... change velocity
  If mc>291
  If 482+md>690
  If md=690

Until KeyboardPushed(#PB_Key_Escape)

Author:  dan yalte [ Thu Apr 18, 2019 12:07 am ]
Post subject:  Re: speed of sprite animation to the screen

Hi thanks for the information. I know changing the refresh rate or related things was a bad idea to many things can go bad. Setting the frame rate makes sense because timing is everything when moving things on screen. So i bit more reading and playing about are in order.

I may put together a small How to on sprite animation when i am done if i figure this out well enough. like the idea of giving back.

Thanks for your time

Author:  dan yalte [ Thu Apr 18, 2019 8:34 am ]
Post subject:  Re: speed of sprite animation to the screen

thanks for all the help i figured out what controls the seed it id in fact the step rate.
I have a new problem found out some real cool stuff but now i have a new problem

pure basic handles sprite animation in a very cool way but i need more control over what is happening. the the animation loop used in pure basic is cool if you want to move things all over the screen at different rates. here is my new problem.

I want to be able to move one sprite from point a to b without moving anything else i then want to repeat that process with another sprite over and over again. The problem is this.

If I use if statements to test in the loops used to move the sprites it wants to keep rerunning the same loop over and over also if a display a sprite outside the loop used to move the sprites it will short out the loop and just print the sprite at the start and end with no animation at all.

take for example the code below. if i uncomment the last line no animation at all.
with it commented the sprite disappears at the end of the loop. and reruns over and over because of the animation loop.

How can i animate things one at a time where i control whats going on and when .

This is becoming a pain been a long time since this happened too me

If mc>292
md=md+1: DisplaySprite(Deck(A),482+md,15+mc):mc=292
ElseIf DisplaySprite(Deck(A),482,15+mc)
If 482+md>690
If Md=690

Author:  Saboteur [ Fri Apr 19, 2019 9:26 pm ]
Post subject:  Re: speed of sprite animation to the screen

If you uncomment last line, md and mc values are always reset to 0.

Your code is confusing. You could use structures to make your code readable and easy to follow
Structure card

Dim deck.card(40)

deck.card(1).y=deck.card(1).y+mc ; <---- or whatever

DisplaySprite(deck.card(1).sprite, deck.card(1).x, deck.card(1).y)

Author:  dan yalte [ Sat Apr 20, 2019 2:03 am ]
Post subject:  Re: speed of sprite animation to the screen

Yes I was thinking a bit too old school. My main problem seems to be I can't reuse a variable to move a card then reuse it to move another card due to the fact the whole animation is is a loop. so there will need to be a bit of replanning in this case a good thing. in this case more like each card is it's own object I few minor draw backs but it may be better off long term A good bet more then likely.


Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group