playing a movie onscreen [solved]

i am trying to make a game for school with panda3d, and my friend (it is a project for 2) made a totally awesomne movie-like thing for when the game starts.

i got it to load and play on a card, but i cant get the card to exactly match the screen size.

class Splashscreen(ShowBase):

	def __init__(self):
	
		ShowBase.__init__(self)
		self.accept("escape", sys.exit)

		props = base.win.getProperties()
		winX = props.getXSize() 
	 	winY = props.getYSize()
		ratio=winX/winY
		cm = CardMaker('card')
		card = aspect2d.attachNewNode(cm.generate())
		tex=loader.loadTexture('Infection Splash Screen.wmv')
		tex.setLoopCount(1)
		tex.setPlayRate(0.5)
		card.setTexture(tex)
		card.setPos(-1.8,0,-1)
		card.setScale(3.8)
app=Splashscreen()
app.run()

that is the code i currently use. it ALMOST fits.

i am mostly concerned about whether or not this will work on computers with a different resolution, and getting a perfect fit would be nice too.

all help appreciated

If you want the card to stretch to fill the entire window (potentially stretching it), then you might parent it to render2d. Since render2d runs, I believe, from -1 to 1 along both axes, its size is 2 in each direction. Thus, scale the card to be of size 2 and move it to sit at -1, -1 (since the origin of the card should be at the bottom left, I believe). Like so:

card = render2d.attachNewNode(cm.generate())
card.setScale(2, 1, 2)
card.setPos(-1, 0, -1)

If, on the other hand, you want to keep the card’s aspect ratio the same, avoiding stretching but potentially incurring empty space either above or below, then perhaps use aspect2d, similarly to render2d above:

card.reparentTo(aspect2d)
card.setScale(2, 1, 2)
card.setPos(-1, 0, -1)

Finally, if you want to use pixel sizes, you can use pixel2d. Note that this places the origin at the top-left, I believe. Presuming a straightforward display region setup, and stretching the card if the aspect ratios of the movie and window are not the same:

width = base.win.getActiveDisplayRegion(0).getPixelWidth()
height = base.win.getActiveDisplayRegion(0).getPixelHeight()
card.reparentTo(pixel2d)
card.setPos(0, 0, -height)
card.setScale(width, 0, height)

those are the options i had tried before as well.

with render2d, the stretching is just too much, probably because of my full-hd monitor, but i want it to work on that too.

on aspect2d, the card only fills a part of the screen.
it looked like 1/4th but when i doubled the scales, part of it fell offscreen. (like i had it in the code i first posted)

and with pixel2d, the card is stretched a big lot in the horizontal axis, and fills half the vertical axis. i doubled vertical scale, but a small portion of the screen to the right is still black.

any new suggestions other than fiddling the scales?
maybe you can explain how to adjust the film size of the aspect2d camera?

Perhaps it might be worth asking: what are the dimensions of the movie, and how do you want it to fit? You’ve said that you want a complete coverage of the screen, but I don’t see how that might work on arbitrary resolutions without negative space on either the sides or above and below (presuming that you centre the movie).

You say that it only fills a part of the screen under aspect2d; do you mean that there is space left all around, or only above, only below, only to one side, or some combination of these?

(It occurs to me that we may be misunderstanding each other - or simply I misunderstanding you - perhaps a screenshot of your current results and a mock-up of you desired results would help.)

I don’t think that changing the film size should be called for, or would be likely to help here, I’m afraid.

i cant seem to get images in here.
i changed the background color of the game to white, and now i can see that the texture doesnt properly fit the card.

any ideas on how to fix THIS issue? the rest will then probably solve itself

edit:

your pixel2d code made the card fit the screen size PERFECTLY. now i understand its the texture size that was the problem all this time. its only a little stretched on the x-axis, but that is my monitor, just too wide :wink:

[edit]

Nevermind, then - I’m glad that you got it working! :slight_smile:

Since you’re still seeing some stretching, the following may still be of some use to you.

[/edit]
Original post:

Well, what do you mean by it not properly fitting? Do you mean that it’s stretched?

If so, then indeed - it was silly of me to miss it, and I do apologise.

Looking at your code, you seem to be generating a card and then applying a uniform scale to it. If your movie’s aspect ratio isn’t square, then applying the texture to the result of cardmaker’s generate method - which produces a square card - would presumably produce distortion.

What I suggest then is determining the aspect ration of your movie, and then using that to apply a scale to each dimension of the card, multiplied by whatever base scale you want. For example, if your movie is has a resolution of 600x300, then we want a horizontal scale of 2; if it’s 400x600 then we want a vertical scale of 1.5. Then, in the former case, you might have:

card.setScale(2, 1, 1)

or in the latter:

card.setScale(1, 1, 1.5)

Note that, if I’m not much mistaken, if you want to use the scalings that I mentioned earlier in order to fit the card to the screen, you likely want a maximum scale of 2 on any given axis, and so might find that doing the inverse is better. For example, in the latter case above:

# The proper scale to fit the screen, I believe.
hScale = 2.0
vScale = 2.0

# This might be more properly calculated;
#  for the sake of example I'm just using a number.
hStretch = 1.0  # No change to the horizontal axis
vStretch = 1.5  # The image is larger on the vertical axis

hScale /= vStretch
vScale /= hStretch

card.setScale(hScale, 1, vScale)

I think that the above is correct. You might also calculate the aspect ration, apply that to both scale values, and then normalise them to whatever base scale you prefer.

or, i just get my friend to remake the movie in a square field of powers-of-2

that would probably be just as much a solve to my problem :smiley:

Bah, that would be doing things the easy way! :stuck_out_tongue_winking_eye:

sometimes the easy way is the best way, saves me valuable calculating time for when the game gets closer to finishing

oh, almost forgot:

thank you a LOT for your help.
saved my bacon there fella :wink: (and my grade)