How to locate scene over the hud Andengine - opengl-es-2.0

Can anybody help me with some solution or example?
Problem in this:
I have a scene and attached hud, i want to locate scene over the hud.
I think i want to dig at zindex path or what?
Thanks, Sorry for my eng :/
PS.Like a dark overlay

private void createHUD() {
gameHUD = new HUD();
scoreText = new Text(70, 420, resourcesManager.fontgame,"Score: 0123456789", new TextOptions(HorizontalAlign.LEFT),vbom);
//scoreText.setColor(android.graphics.Color.rgb(253, 193, 7));
scoreText.setColor(Color.WHITE);
scoreText.setAnchorCenter(0, 0);
scoreText.setText("Score: 0");
heart1 = new Sprite(760, 460, resourcesManager.heart_region, vbom);
heart2 = new Sprite(710, 460, resourcesManager.heart_region, vbom);
heart3 = new Sprite(660, 460, resourcesManager.heart_region, vbom);
gameHUD.attachChild(scoreText);
gameHUD.attachChild(heart1);
gameHUD.attachChild(heart2);
gameHUD.attachChild(heart3);
camera.setHUD(gameHUD);
}

You can add scene to hud layer which having any rectangle entity as child. i think it may work.

Related

Label position in layout breaks after trying to resize the window after using QPropertyAnimation

I have the following problem: I'm trying to animate a QLabel, more specifically to make it fadeIn using QPropertyAnimation. It animates successfully, but when I'm trying to resize the window, the label breaks out of the layout that's in, making it overlap with the other items.
The code:
self.label = QtWidgets.QLabel(self.frame)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setStyleSheet("color: #fc8102;\n"
"font-weight: bold;\n"
"font-size: 18px;")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.opacity_effect = QtWidgets.QGraphicsOpacityEffect(self.label)
self.opacity_effect.setOpacity(0)
self.label.setGraphicsEffect(self.opacity_effect)
self.anim = QtCore.QPropertyAnimation(self.opacity_effect, b'opacity')
self.anim.setDuration(800)
self.anim.setStartValue(0)
self.anim.setEndValue(1)
self.anim.start()
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.verticalLayout.addWidget(self.label)
Image with what's happening:
Image with how it's supposed to look:
Thanks in advance.

How to prevent a shape behind a clicked shape to trigger in createjs

My very first question to stackoverflow, so please be kind.
I have two shapes on a createjs stage. The first one background covers the whole stage and has a listener on click defined. I want to put another shape on this one and this one should not trigger the click-listener defined on the background.
In the following example a click on the red circle triggers the listener of background.
var stage = new createjs.Stage('c');
var rect = new createjs.Shape();
rect.graphics.beginFill('#0000ff').drawRect(0, 0, 50, 50);
var background = new createjs.Shape();
background.graphics.beginFill('#000000').drawRect(0, 0, 500, 500);
background.alpha = 0.7;
background.on('click', function () {
circle.visible = !circle.visible;
stage.update();
});
var circle = new createjs.Shape();
circle.graphics.beginFill('#ff0000').drawCircle(225, 225, 50);
// circle.on('click', function () {});
stage.addChild(rect);
stage.addChild(background);
stage.addChild(circle);
stage.update();
https://codepen.io/anon/pen/rKmPOY
I found, that if I put an empty click listener on the circle, I have what I want, but this feels awkward.
What is the right approach here? This shouldn't be a bubbling issue since background and circle are siblings. Or am I getting this completly wrong?
If something doesn't have a click listener, it will not be evaluated when the mouse is clicked. This is definitely a desired behaviour (it is much more annoying to have things you don't want blocking clicks).
Your workaround adding an empty listener is fine, and pretty typical.
The only other option I can think of is to check what is under the mouse on click, and filter it manually, which is way more work.
Cheers,

Drawing on an image before drawing on screen in XNA using VB.NET

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!
SpriteBatch works with XNA Texture2D objects, whereas Bitmap and Image are System.Drawing types. They do not work together.
You can create a new RenderTarget2D, set it as active using GraphicsDevice.SetRenderTarget() and draw there using a SpriteBatch. You can then draw the stored render target to screen using a SpriteBatch, since render targets are a type of Texture2D.
So I've experimented with Petri Laarne's answer 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, and thank's for the initial answer #Petri Laarne

Using WriteableBitmapEx

I am currently developing metro apps and I need to write text On images.
I found this http://writeablebitmapex.codeplex.com/
But I am new to XAML and dosent know how to use it specifically.
So can anyone say me how do I use it in order to write text on image.
As I have asked this question on MSDN but I have no reply yet.
Edit:
If I use as Muad'Dib I am getting the error as seen in below screenshot:
The Error is: 'Writeable Bitmap Extensions' is ambiguous in the namespace 'System.Windows.Media.Imaging'
there is one possible solution in the Discussions area for WriteableBitmapEx
here is the code from that "article":
public static void DrawText(this WriteableBitmap wBmp,Point at, string text,double fontSize,Color textColor)
{
TextBlock lbl = new TextBlock();
lbl.Text = text;
lbl.FontSize = fontSize;
lbl.Foreground = new SolidColorBrush(textColor);
WriteableBitmap tBmp = new WriteableBitmap(lbl, null);
wBmp.Blit(at, tBmp, new Rect(0, 0, tBmp.PixelWidth, tBmp.PixelHeight), Colors.White, System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.Alpha);
}

How to make AppStore-like buttons on iPad

I can't seem to figure out how to do subject.
What I would like is to have some buttons which are not round-rect buttons.
The iPad AppStore has e.g. the search controls which mimics a dropdown known from e.g. the web select box or dropdown from Windows.
How do I create a button that looks more like a UIBarButtonItem than a RoundRect UIButton, and still being able to place it anywhere?
I'm working in MonoTouch, but answers can come in any flavour, how to do it through Interface builder or programmatically in objective-c or MonoTouch, or even just a pseudo description - im just hoping to get a hint.
Hope someone out there can lead me in the right direction...
/Anders
Just create a custom button. Here's an example to create a real ugly custom button using some features of UIView and CALayer.
var btn = UIButton.FromType(UIButtonType.Custom);
btn.Frame = new RectangleF(100, 100, 150, 30);
btn.SetTitle("Button", UIControlState.Normal);
// Custom backround image.
btn.SetBackgroundImage(UIImage.FromFile("./images/barbuttonbackground.png"), UIControlState.Normal);
// Custom border color.
btn.Layer.BorderColor = UIColor.Orange.CGColor;
// Custom border width.
btn.Layer.BorderWidth = 2.0f;
// Custom rounded corners (does not really work well together with the background image).
btn.Layer.CornerRadius = 10.0f;
// Transparency.
btn.Alpha = 0.6f;
window.AddSubview(btn);
Adjust it to your needs. If you want to have your buttons look differently, go ahead.
There are some custom controls in the web that you can use for your purpose, e.g. MAConfirmButton which replicates the App Store's "Buy Now" buttons.
Heres my sample of how I do it in MonoTouch at the moment.
Since i'm not using colors I have commented out the section with the colorlayer - but kept it for reference.
public static UIButton GetNewButton(RectangleF frame)
{
var btn = UIButton.FromType(UIButtonType.Custom);
btn.Frame = frame;
btn.Layer.BorderWidth = 1.0f;
btn.Layer.BorderColor = UIColor.FromRGB(200,200,200).CGColor;
btn.Layer.CornerRadius = 4.0f;
btn.SetTitleColor(UIColor.Black, UIControlState.Normal);
btn.TitleLabel.TextAlignment = UITextAlignment.Right;
btn.TitleLabel.BackgroundColor = UIColor.Clear;
btn.Layer.NeedsDisplayOnBoundsChange = true;
SetupLayers(btn);
return btn;
}
private static void SetupLayers(UIButton btn){
CAGradientLayer bevelLayer = new CAGradientLayer();
bevelLayer.Frame = new RectangleF(new PointF(0,0), btn.Frame.Size);
bevelLayer.Colors = new CGColor[]{UIColor.White.CGColor, UIColor.FromRGB(218,218,218).CGColor};
bevelLayer.CornerRadius = 4.0f;
bevelLayer.NeedsDisplayOnBoundsChange = true;
/* CALayer colorLayer = new CALayer();
colorLayer.Frame = new RectangleF(0f,1f, btn.Frame.Width, btn.Frame.Height -2);
colorLayer.BorderColor = UIColor.FromWhiteAlpha(0, 0.1f).CGColor;
colorLayer.BackgroundColor = UIColor.FromRGBA(0.220f, 0.357f, 0.608f, 1).CGColor;
colorLayer.BorderWidth = 1.0f;
colorLayer.CornerRadius = 4.0f;
colorLayer.NeedsDisplayOnBoundsChange = true;
*/
CAGradientLayer colorGradient = new CAGradientLayer();
colorGradient.Frame = new RectangleF(0f,1f, btn.Frame.Width, btn.Frame.Height -2);
colorGradient.Colors = new CGColor[]{UIColor.FromWhiteAlpha(1f, 0.1f).CGColor, UIColor.FromWhiteAlpha(0.2f, 0.1f).CGColor/*, null*/};
colorGradient.Locations = new NSNumber[]{NSNumber.FromFloat(0.0f), NSNumber.FromFloat(1.0f)};
colorGradient.CornerRadius = 4.0f;
colorGradient.NeedsDisplayOnBoundsChange = true;
btn.Layer.AddSublayer(bevelLayer);
// btn.Layer.AddSublayer(colorLayer);
btn.Layer.AddSublayer(colorGradient);
btn.BringSubviewToFront(btn.TitleLabel);
}