Variable sprite speed

Anything related to Hollywood Designer goes in here
Post Reply
User avatar
r-tea
Posts: 80
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland
Contact:

Variable sprite speed

Post by r-tea » Tue Jun 19, 2018 10:19 pm

Hi!
I did my first try with Sprites and drawing.
It's a randomly moved circle.
There are two things that surprised me.
1. sprite often changes its speed significantly. The speed is constantly set to 1.
2. sprite's paths are not straight lines
Twice: why?

Code: Select all

@VERSION 2,0

@DISPLAY {Width = 640, Height = 480}
@SAMPLE 10, "Bells.wave"

/*
** Make the sprites. We create two sprites from each form: One for the
** background and one that is displayed below the mouse pointer.
*/
Function p_CreateSprites()
        ; Circle
		SetFillStyle(#FILLCOLOR)
        CreateBrush(10, 12, 12)
        SelectBrush(10)
        Circle(0, 0, 6, #WHITE)
        EndSelect
        SetBrushTransparency(10, #BLACK)
        CreateSprite(1, #BRUSH, 10)
EndFunction



p_CreateSprites()

x1=0
y1=0
DisplaySprite(1, x1, y1)

Function p_MoveRnd()
	x=Rnd(634)
	y=Rnd(474)
	Circle(x,y,3,#RED)
	MoveSprite(1, x1, y1, x, y, {Speed=1})
	PlaySample(10)
	Circle(x,y,3,#BLACK)
	x1=x
	y1=y
EndFunction

EscapeQuit(True)
SetInterval(1, p_MoveRnd, 40)

;
; main loop!
;
Repeat
        WaitEvent
Forever

User avatar
airsoftsoftwair
Posts: 2558
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

Re: Variable sprite speed

Post by airsoftsoftwair » Fri Jun 22, 2018 3:34 pm

Don't use MoveSprite(). To move a sprite to a new position just call DisplaySprite() with the new position. MoveSprite() is a very old function of very limited practical use. And yes, the name is misleading but it got its name somewhen in 2001 or so ;-)

User avatar
r-tea
Posts: 80
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland
Contact:

Re: Variable sprite speed

Post by r-tea » Sun Jun 24, 2018 11:26 pm

Ok, but DisplaySprite() just blanks the sprite on the old position, and display it instantly again in a new position, without displaying all the indirect positions. If MoveSprite() is not recomended then what alterative is there?

SamuraiCrow
Posts: 171
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: Variable sprite speed

Post by SamuraiCrow » Mon Jun 25, 2018 12:12 pm

Use the law of cosines to find the direction of the difference of the coordinates and then convert the vector back to rectangular coordinates using sine and cosine. Just watch out for horizontal and vertical cases because they can result in an invalid angle so just do them manually using sign comparisons.

User avatar
r-tea
Posts: 80
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland
Contact:

Re: Variable sprite speed

Post by r-tea » Mon Jun 25, 2018 5:39 pm

@SamuraiCrow
But it doesn't resolve the problem of speed.

EDIT:
Oh, you might have in mind DisplaySprite() to take evaluated coords. Am I right?
I was thinking you're refering to MoveSprite() at first.

SamuraiCrow
Posts: 171
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: Variable sprite speed

Post by SamuraiCrow » Mon Jun 25, 2018 10:39 pm

r-tea wrote:
Mon Jun 25, 2018 5:39 pm
@SamuraiCrow
But it doesn't resolve the problem of speed.

EDIT:
Oh, you might have in mind DisplaySprite() to take evaluated coords. Am I right?
I was thinking you're refering to MoveSprite() at first.
DisplaySprite() is what I'm referring to. The speed is 1 by default when using trigonometric unit vectors. If you want it to be a different speed, multiply the unit vectors by the speed while they are still in polar notation.

User avatar
airsoftsoftwair
Posts: 2558
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

Re: Variable sprite speed

Post by airsoftsoftwair » Mon Jun 25, 2018 11:56 pm

By the way, if you non-perfect vsync'ed refresh by "variable speed", then you have to use a plugin like GL Galore or RebelSDL which uses hardware double buffering. Hollywood's default display driver is software-based and thus doesn't offer perfect vsyncing which can lead to a few glitches when moving sprites. If you need perfect vsync'ing, you need to use GL Galore or RebelSDL because those two offer hardware double buffering. Then the speed will be completely smooth.

User avatar
r-tea
Posts: 80
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland
Contact:

Re: Variable sprite speed

Post by r-tea » Tue Jun 26, 2018 8:54 pm

SamuraiCrow wrote:
Mon Jun 25, 2018 10:39 pm
DisplaySprite() is what I'm referring to. The speed is 1 by default when using trigonometric unit vectors. If you want it to be a different speed, multiply the unit vectors by the speed while they are still in polar notation.
As Hollywood's documentation stands DisplaySprite() doesn't have a speed argument.

SamuraiCrow
Posts: 171
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: Variable sprite speed

Post by SamuraiCrow » Tue Jun 26, 2018 10:22 pm

I am telling you how to do the math to make it yourself. It takes some basic trigonometry.

Post Reply