Hud draw above rotated screen [SOLVED]


(Daniel Berg) #1

Hi, I have a slight problem. I have a game where I rotate the screen by setting the FP.screen.angle value based on user input. Now I wanna draw a hud ontop of this, without rotating said hud. I found a solution where I make an image of the current FP.buffer, rotate and render that, then render the hud ontop. @zachwlewis wrote this: https://github.com/zachwlewis/FlashPunk-Screen-Rotation

Now this solution works, problem is that it wreaks havoc on my camera movement, screen centering and so forth. I do some stuff with scaling and have to work with a tricky aspect ratio for this kind of game.

What I figured is that entity have a renderTarget var that I can give a custom bitmapData, is it possible to just give the hud a custom render target, and rendering this ontop of the existing FP.buffer? Am I way of here? If not how do I go about doing this. I’ve feebly attempted this but to no avail. Is there a simpler way of doing what I want or do I have to rewrite alot of my code to make the aforementioned solution work with my setup?


(Daniel Berg) #2

Well, I solved it. Not how I initially expected. But I just thought of the debug console. It does exactly what I wanted, so I modeled the hud after that. I created some sprites, textfields and called FP.engine.addChild(). It works perfectly.

So I guess I posted this in some haste, should I keep the thread or delete it? I guess it could be usefull if someone else is wondering the same thing.


(Jacob Albano) #3

I’d say keep it. I was wracking my brains to figure out how I might help with this, and using the display list never occurred to me.


(azrafe7) #4

I was going to propose a similar solution… if you need to use Graphic classes from FlashPunk you can:

  • make a BitmapData big as the screen (or as your hud)
  • create a Bitmap with that
  • add the latter as a child to Engine (or Stage)
  • directly render to the BitmapData of step 1

Edit: As a bonus, with this approach, you could add your HUD Entity to the world regularly, set its visible property to false (so that it gets updated but not rendered), and draw it in an overridden Engine/World.render() method (possibly via HUDEntity.graphic.render(bitmapData, FP.zero, FP.zero).

I’ll add that I’ve not tested it, but should work.


(Daniel Berg) #5

I’ll keep that in mind for further projects. BTW I just realized that I have been using your Vec2 class for a game I made previously in flashpunk. Was browsing some of my bookmarks for a link and connected your username. Thanks for that :slight_smile: and to the original creator.

I’ve been working on a game for about a year that was originally made with XNA that I ported over to MonoGame(if you can call it porting). I’m so used to working with 2d vectors that when I first started coding in ac3 I felt rather disoriantated without it. That led me to Playchilla which led me to your implementation.


(Daniel Berg) #6

While I’m at it. Turns out I’ve been using most of your preloader code I found on this forum a while back. Thanks a ton for that. I didn’t know this either until I was making a preloader for my current game, when I recognized your name. I oc include your name and azrafe7 in the source code with links. Both my previous game and this one will be open source when I’m done.

Don’t know forum protocols very well, unsure if I should be posting this in a help thread but I figure I started it and its been solved twice over so what the heck.

Thanks to you both


(Jacob Albano) #7

I’m glad I could be of service! :heart:

Some forums are very strict about off-topic comments, but I think since this thread has already been solved and the additional comments aren’t distracting its quite alright.


(azrafe7) #8

You’re very welcome. And don’t forget to post a link to your opensource project in the forums when you’re done, I’d be glad to see what you’ve come up with! :smirk:


(David Williams) #9

The original FlashPunk forums were never very strict when it came to situations like this. As long as the topic was in the correct sub-category and not spam, it was alright to stray a little here and there.


(Jacob Albano) #10

Oh yeah, I know. I was referring to other forums I’ve been on in the past. I like to think we’re too cool to worry about that here. :wink: