1
\$\begingroup\$

I'm programming a game in XNA, using VB.NET. I want to create an intro to the game that zooms in/out the whole screen and scaling each image to accomplish this is cumbersome at best. I like to be able to draw a lot of .PNG's (or parts of them) onto a whole image, to then be able to manipulate (scale, turn etc) that whole image, before drawing it with the spriteBatch. The examples I can find use something like:

dim bitmap as New Bitmap

or

dim image as New Image

but these codes highlights the "Bitmap" or "Image" as red, and I cannot use them. I'd be thankful for any help on this issue!

please note: I'm new to this, and self taught, so I prefer concrete examples if possible.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ You need to look into the Content Management system that is built into XNA. This is not how you load a usable resource. You have a lot of reading ahead of you. msdn.microsoft.com/en-us/library/bb203887.aspx \$\endgroup\$
    – jgallant
    Jun 23, 2016 at 12:18
  • \$\begingroup\$ Yeah, I could also submit to a 4 year education, but I already have one in another discipline, and helping people with problems regarding that expertise. So the purpose here has to be to help me where I am, and not pointing to an all-encompassing article that I don't understand a lot of the words in (because it presupposes that I already know a lot of basic constructs). Sure, don't get me wrong, I'm all about reading if it doesn't require previous education, takes a week and can give me answers to my questions. @Jon \$\endgroup\$ Jun 23, 2016 at 12:31
  • 1
    \$\begingroup\$ I pointed you to that documentation. The code you pasted above demonstrates that you have no understanding at all about the content pipeline. You need to get a clear understanding of its functionality before you attempt to load images into your project. Or you could just be ignorant, and try to wing it like you are now. Voting to close as this question is asking about how to get started. \$\endgroup\$
    – jgallant
    Jun 23, 2016 at 12:34
  • \$\begingroup\$ And feelings got hurt. There's a lot of things I don't have understanding about, which is why I can post questions on this forum for answers. If I knew everything there is to know, I'd never ask a question here, and the forum would become obsolete. If you don't know the answer yourself, or if you are so smug that you first post meaningless answers and then become butthurt when they aren't received with praises - just don't bother wasting your own or anyone elses time doing it. @Jon \$\endgroup\$ Jun 23, 2016 at 12:40
  • 2
    \$\begingroup\$ I'm not trying to hurt your feelings. I am also not trying to hold your hand. My point to you is that this is the very basics of XNA. You are loading your content into an Image Object type, which is not how you are supposed to load content into XNA. You could fix the "Red" errors by importing System.Drawing assembly, but that will not solve your problem. You need to be aware of how to do this properly. This is something that a basic tutorial should explain to you. This is something you need to understand to use XNA. \$\endgroup\$
    – jgallant
    Jun 23, 2016 at 12:47

1 Answer 1

0
\$\begingroup\$

So I've experimented with Petri Laarne's answer from StackOverflow and finally come up with a workable code (most examples online are using C#, and doesn't explain the entire process). Trying to explain it here:

In Public Class Game1:

Private WithEvents graphics As GraphicsDeviceManager
Private WithEvents spriteBatch, spriteBatch2 As SpriteBatch

In Loadcontent:

Public render2 As RenderTarget2D
spriteBatch2 = New SpriteBatch(GraphicsDevice)
spriteBatch = New SpriteBatch(GraphicsDevice)
render2 = New RenderTarget2D(GraphicsDevice, 1024, 768)

In Draw:

spriteBatch2.GraphicsDevice.SetRenderTarget(render2)
        GraphicsDevice.Clear(Color.Black)
        srcRect = New Rectangle(440, 0, 440, 440) : destRect = New Rectangle(100, 335, 440, 440)
        spriteBatch2.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend) : spriteBatch2.Draw(introNEWMirrorDecos, destRect, srcRect, Color.White) : spriteBatch2.End()
        destRect = New Rectangle(300, 335, 440, 440)
        spriteBatch2.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend) : spriteBatch2.Draw(introNEWMirrorDecos, destRect, srcRect, Color.White) : spriteBatch2.End()
        spriteBatch2.GraphicsDevice.SetRenderTarget(Nothing)
        GraphicsDevice.Clear(Color.Black)
        destRect = New Rectangle(512, 384, 1024, 768) : srcRect = New Rectangle(0, 0, 1024, 768)
        spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend) : spriteBatch.Draw(render2, destRect, srcRect, Color.White, PI / 12, New Vector2(512, 384), SpriteEffects.None, 0) : spriteBatch.End() 

This is an example code from the actual game that worked like it was intended: drawing 2 things on the alternate rendering image and then drawing them as one single image (in this case being able to rotate it by pi/12).

Any comments on how to do this differently or more efficient is appreciated

\$\endgroup\$
1
  • \$\begingroup\$ I'd like to forward a comment from @Petri Laarne here too, to clarify some things: "That is correct. You can even use the same SpriteBatch instance, as long as you call GraphicsDevice.SetRenderTarget(...) as in the current version. Additionally, if the scene drawn to the render target is static, you can skip redrawing it." \$\endgroup\$ Jun 24, 2016 at 9:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .