Login or Signup

Blitz3D Docs -> 2D - A-Z -> D -> DrawMovie

DrawMovie movie,[x,y][,width,height]


movie - movie handle
x (optional) - position of top left point of movie. Defaults to 0.
y (optional) - position of top left point of movie. Defaults to 0.
width (optional) - width of movie. Defaults to movie width.
height (optional) - height of movie. Defaults to movie height.


Viewport and origin are not taken into account, and the movie must be positioned entirely 'on screen', otherwsie nothing will be drawn.

Movie support relies on DirectShow, so you will need to ensure the correct drivers are installed. Movies will typically playback fastest at their natural size.

When playing MPEG or AVI files, the movie is played back at normal speed 'behind the scenes', and DrawMovie simply draws the most recent frame. For animated GIFs, the DrawMovie command simply draws the next frame of the animation each time it is called, so you need to manage your animation timing manually. See the example below for details.

See also: OpenMovie, CloseMovie, MoviePlaying, MovieWidth, MovieHeight.


; Movie Commands Example
; ======================
; This demonstrates the following commands:
;	OpenMovie
;	MovieHeight
;	MovieWidth
;	MoviePlaying
;	DrawMovie

; Some constants to start with
Const WIDTH = 640
Const HEIGHT = 480

; First of all, set up the graphics
SetBuffer BackBuffer()
ClsColor 0,0,0
Color 0,255,0

; Next, open the movie file.  Feel free to change this to an AVI or MPEG file.

; check to see if it loaded okay
If movie=0 Then RuntimeError "Error - Movie not loaded!"
If Not(MoviePlaying(movie)) Then RuntimeError "Error - Movie not playing!"

;Now determine the size of the movie
w=MovieWidth(movie)     ; the width of the movie
h=MovieHeight(movie)    ; the height of the movie

; Now set up the starting position and timing variables
x=(WIDTH-w)/2           ; the x position of the movie on screen
y=(HEIGHT-h-100)/2      ; the y position of the movie on screen
period=100              ; the interval between frames
time=MilliSecs()        ; the time of the last frame update

; And here's the main loop

; Wait for the specified period

; GIFs have no timing info, and as such will redraw the next frame on each call to DrawMovie.
; AVIs and MPEGs do have timing info, and as such will redraw the most recent frame on each call to DrawMovie.
; Ergo, this time limiter only has an impact, and is only required for GIFs.
; do nothing
Until MilliSecs()-time>=period
time=MilliSecs()    ; save the current time for the next frame

; Handle keyboard inputs

; CONTROL adjusts the speed with which we do stuff	
If KeyDown(29) Or KeyDown(157) Then
End If

; SHIFT means we're dealing with the size
If KeyDown(42) Or KeyDown(54) Then
	If KeyDown(203) And w>change-1 Then w=w-change
	If KeyDown(205) And x+w+change < WIDTH Then w=w+change
	If KeyDown(200) And h>change-1 Then h=h-change
	If KeyDown(208) And y+h+change < HEIGHT Then h=h+change
	; otherwise it's the position that we're changing
	If KeyDown(203) And x>change-1 Then x=x-change
	If KeyDown(205) And x+w+change < WIDTH Then x=x+change
	If KeyDown(200) And y>change-1 Then y=y-change
	If KeyDown(208) And y+h+change < HEIGHT Then y=y+change

; +/- to change the animation speed
If ( KeyDown(13) Or KeyDown(78) ) And period>change Then period=period-change
If ( KeyDown(12) Or KeyDown(74) ) And period < 500 Then period=period+change

; Redraw the screen, by...

Cls                         ; clear the screen
DrawMovie movie,x,y,w,h     ; draw the movie
; draw the instructions
Text 0,0,"Use the arrow keys to reposition the movie."			
Text 0,20,"Hold SHIFT with the arrow keys to resize."					
Text 0,40,"Use + or - or control the animation speed."
Text 0,60,"Hold CONTROL to resize, move, or change speed faster."	
Text 0,80,"Press ESCAPE to exit."
Text 0,100,"Current Command Syntax: DrawMovie(movie, " + x + ","+ y + "," + w + "," + h + ")"
; Flip the buffers

Until KeyHit(1) ; Escape to exit

; Remove the movie from memory before closing down

End ; bye!


Ben(t)(Posted 1+ years ago)
This doesn't work for me! I replaced the hat.gif with my own gif but it still doesn't work

Knight #51(Posted 1+ years ago)
me neither.

John Blackledge(Posted 1+ years ago)
See this thread:

Blitz3D Manual Forum

BlitzPlus Equivalent Command
Blitz Social Club