It is currently Wed Aug 21, 2019 2:19 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: speed of sprite animation to the screen
PostPosted: Wed Apr 17, 2019 12:48 am 
Offline
User
User

Joined: Thu Aug 13, 2015 8:56 am
Posts: 43
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.....


Top
 Profile  
Reply with quote  
 Post subject: Re: speed of sprite animation to the screen
PostPosted: Wed Apr 17, 2019 9:09 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 11, 2006 12:07 am
Posts: 489
Location: Germany / one of the fishheads
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.

_________________
PB 5.62, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 51y
"Happiness is a pet." | "Never run a changing system!"


Top
 Profile  
Reply with quote  
 Post subject: Re: speed of sprite animation to the screen
PostPosted: Wed Apr 17, 2019 10:12 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 7:09 pm
Posts: 245
Location: (Madrid) Spain
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.

_________________
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti


Top
 Profile  
Reply with quote  
 Post subject: Re: speed of sprite animation to the screen
PostPosted: Wed Apr 17, 2019 2:52 pm 
Offline
User
User

Joined: Thu Aug 13, 2015 8:56 am
Posts: 43
mc=mc+1
If mc>291
md=md+1: DisplaySprite(1,482+md,15+mc):mc=291
ElseIf DisplaySprite(1,482,15+mc)
EndIf
If 482+md>690
DisplaySprite(1,482+md,15+mc):md=690
EndIf
If md=690
DisplaySprite(1,691,307)
EndIf
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: speed of sprite animation to the screen
PostPosted: Wed Apr 17, 2019 4:33 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 7:09 pm
Posts: 245
Location: (Madrid) Spain
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.

Code:
InitSprite()
InitKeyboard()

OpenWindow(0,100,100,800,600,"")
OpenWindowedScreen(WindowID(0),0,0,800,600)

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

CreateSprite(1,90,50)
StartDrawing(SpriteOutput(1))
  Box(0,0,90,50,RGB(128,90,45))
StopDrawing()

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

Repeat
  While(WindowEvent())
  Wend
 
  ClearScreen(RGB(255,0,255))
   
  acceleration+0.1
  If (acceleration>10)
    acceleration=10
  EndIf
 
  mc=mc+acceleration       ;  <----- changing this to a fix value: 1, 2, 5, 10..... change velocity
  If mc>291
    md=md+acceleration
    DisplaySprite(1,482+md,15+mc)
    mc=291
  Else
    DisplaySprite(1,482,15+mc)
  EndIf
 
  If 482+md>690
    DisplaySprite(1,482+md,15+mc)
    md=690
  EndIf
 
  If md=690
    DisplaySprite(1,691,307)
  EndIf

  ExamineKeyboard()
 
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)

_________________
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti


Top
 Profile  
Reply with quote  
 Post subject: Re: speed of sprite animation to the screen
PostPosted: Thu Apr 18, 2019 12:07 am 
Offline
User
User

Joined: Thu Aug 13, 2015 8:56 am
Posts: 43
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


Top
 Profile  
Reply with quote  
 Post subject: Re: speed of sprite animation to the screen
PostPosted: Thu Apr 18, 2019 8:34 am 
Offline
User
User

Joined: Thu Aug 13, 2015 8:56 am
Posts: 43
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


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


Top
 Profile  
Reply with quote  
 Post subject: Re: speed of sprite animation to the screen
PostPosted: Fri Apr 19, 2019 9:26 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 7:09 pm
Posts: 245
Location: (Madrid) Spain
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
Example:
Quote:
Structure card
sprite.i
x.i
y.i
dest_x.i
dest_y.i
direction.i
speed.i
EndStructure

Dim deck.card(40)

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

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

_________________
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti


Top
 Profile  
Reply with quote  
 Post subject: Re: speed of sprite animation to the screen
PostPosted: Sat Apr 20, 2019 2:03 am 
Offline
User
User

Joined: Thu Aug 13, 2015 8:56 am
Posts: 43
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.

Thanks


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye