Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Drawing sprite into rectangle - Problem

Started by Hoover85 3 replies 400+ views
Original Post
Hoover85
Hoover85
How can I draw more than one sprite with different SpriteFlags using Direct3D? The problem is that I have two sprites; one with SpriteFlags.AlphaBlend and the other one with SpriteFlags.None. I can't quite figure out how could I get this to work. I tried to do this with following lines of code under my render method:

' This one needs to have the transparency feature.
spriteTest1.Begin(SpriteFlags.AlphaBlend()
Dim rPicture1 As Rectangle = New Rectangle(0, 0, 50, 50)
spriteTest1.Draw(texture1, rPicture1, New Vector3(0, 0, 0), New Vector3(0, 0, 0), Color.White)
spriteTest1.End()

' The other sprite does not need transparency!
spriteTest2.Begin(SpriteFlags.None)
Dim rPicture2 As Rectangle = New Rectangle(50, 0, 50, 50)
spriteTest2.Draw(texture2, rPicture2, New Vector3(0, 0, 0), New Vector3(0, 50, 0), Color.White)
spriteTest2.End()





I was able to get visual with using one sprite that had transparency, but it looked kinda wrong. Meaby I still haven't figures out the idea with these rectangle and the sprite coordinates. Somehow they just feel difficult when you need to give two different coordinates for using one sprite. And when I input the coordinates for sprite, I haven't understood that should the coordinates be inserted by the screen coordinates or by the rectangle coornates where the sprite is being drawn. [Edited by - Hoover85 on July 3, 2006 5:36:18 AM]
Hoover85
Hoover85
Aaaa-ha! Now I have these two sprites visible!

But I still don't understand the coordinates. Why there are two different coordinates? I can't get the sprites into the locations I want or they only are partly visible.
Hoover85
Hoover85
Could someone please explain how these coordinates work, when I want to draw a sprite into a rectangle and make it move with the mouse coordinates?

The picture I'm using with this, is a 50x50 pixels .bmp picture.

spritePicture.Begin(SpriteFlags.AlphaBlend)Dim r As Rectangle = New Rectangle(New Point(0, 0), New System.Drawing.Size(50, 50))' Define the middle point of the picture and tell the picture to move by mouse coordinates.' This works like a crosshair.spritePicture.Draw(textureCrosshair, r, New Vector3(25.0F, 25.0F,  0.0F), New Vector3(xMouseCoord, yMouseCoord, 0), Color.White)spritePicture.End()


With the code above, the crosshair is not in 1:1 scale, it's somehow deformed and the center is not where the mouse coordinates is.
Hoover85
Hoover85
Hmm... I made couple searches with google and noticed that the textures should always be powers of 2 (1x1, 2x2, ... 32x32, 64x64.... and so on).

So when I resized my 50x50 texture to 64x64, it was in right scale (1:1) and it was in the correct position. But how in the world I can use 800x600 textures, when there are so strict rules... I mean, there has to be a way?

I propably need a texture as high as 1280x720 to meet my requirements with this project.
sirob
sirob
you just use the next power of two and leave the unused portion of the texture unused.

If you can't stand that kind of waste, you could probably use Surfaces instead, and the StretchRect method, but this would suffer a performance penalty.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.