fade effect in blackberry (os 4.5 ) application - blackberry

in my blackberry application i have to create a effect in which fullscreen bitmap is slowly disappearing and ui screen is coming up.
protected void paint(Graphics g) {
g.setGlobalAlpha(globalAlpha);//starting value of globalAlpha is 255.
g.drawBitmap(0, 0, getWidth(), getHeight(), _bitmap, 0, 0);
g.setGlobalAlpha(255 - globalAlpha);
globalAlpha--;
super.paint(g);
}
This code is just for giving demo that what i want.
super.paint(g) is calling 255 times because of that its a poor code.
in one timer task i am calling invalidate();
So any suggestions how to implement this?

If you can get away with using 5.0 APIs, you'll save yourself a LOT of work by using the TransitionContext class. One of the transition types is "fade".

Related

Need help - Monogame 2d water reflection

Ok so i am following this tutorial Water Reflection XNA and when i adjust code with monogame i cant get final result.
So here is my LoadContent code:
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
texture = Content.Load<Texture2D>("test");
effect = Content.Load<Effect>("LinearFade");
effect.Parameters["Visibility"].SetValue(0.7f);
}
and my Draw code:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
//effect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(texture, new Vector2(texturePos.X, texturePos.Y + texture.Height), null, Color.White * 0.5f, 0f, Vector2.Zero, 1, SpriteEffects.FlipVertically, 0f);
spriteBatch.End();
spriteBatch.Begin();
spriteBatch.Draw(texture, texturePos, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
and finally my .fx file: LinearFade
So the problem starts when i apply effect. My texture just disappear and if i comment effect part in Draw method i get mirror image with fade (messing with alpha "Color.White * 0.5f") but without fade effect like he have on tutorial from middle of picture to the bottom of picture. I still dont have much experience in monogame and shader but i am learning.
If any1 know how to fix this or how to make it like on tutorial above it would be nice. Btw sry for bad english not my main language.
Ok no need for help i got it after 2 day of thinking i know the answer. The thing is that you need default vertex shader input and output and then shader is working. So if any1 have problem with shaders in monogame first see if you have default vertex input and output. Will put solution code so if some1 doing same tutorial or similer thing so they know what is the problem.
Solution: Working Effect.fx

Blackberry app is very slow on startup, how can i fix this?

I recently updated my app to work on nearly all of the phones. I did this by having the first screen detect the screen size and then change all the images (there are a lot of images). As such, the startup on the non-base model phones is like 15 seconds, it looks like the phone is freezing but its just changing the images. It does this every time I open the app. What can I do to fix this?
Make sure that you are resizing images on a separate thread (no UI Blocking operation).
It would be better if you store all the resized images on persistent
storage so that you don't need to resize same image twice on a
handset.
[edited]
Some links about how to use persistence storage:
BlackBerry persistent store
Create a persistent data store
BlackBerry Java Application Development Guide
Sample Code Snippet for making a Bitmap object persistable:
class PersistableBitmap implements Persistable {
int width;
int height;
int[] argbData;
public PersistableBitmap(Bitmap image) {
width = image.getWidth();
height = image.getHeight();
argbData = new int[width * height];
image.getARGB(argbData, 0, width, 0, 0, width, height);
}
public Bitmap getBitmapImage() {
Bitmap image = new Bitmap(width, height);
image.setARGB(argbData, 0, width, 0, 0, width, height);
return image;
}
}

What is the easiest way to set background image of the application on Blackberry

I know, this question was asked before. However I can't beleive that this operation is so difficult. I think i miss some important points on developing Blackberry applications.
Try to use the following code:
Bitmap backgroundBitmap = Bitmap.getBitmapResource("background.png");
HorizontalFieldManager horizontalFieldManager = new
HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH |
HorizontalFieldManager.USE_ALL_HEIGHT){
//Override the paint method to draw the background image.
public void paint(Graphics graphics)
{
//Draw the background image and then call super.paint
//to paint the rest of the screen.
graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(),
backgroundBitmap, 0, 0);
super.paint(graphics);
}
};

Do screen transitions when the user clicks on a bitmap

I am working on an eBook app where I need to transition the screens from left to right and right to left. I tried many samples that I've found, but I am not successful. How do I change the screen frequently when user clicks on the screen from left to right and right to left. What is the basic idea for transition of pages. I went through the Developer Support Forum thread "page-flip effect" looking for a solution, but I can't see it.
The following code is not logical. In which position do I have to implement flip effect for flipping pages in the screen and how to implement it?
public class TransitionScreen extends FullScreen implements Runnable{
private int angle = 0;
Bitmap fromBmp,toBmp;
public TransitionScreen(){
}
public TransitionScreen(AnimatableScreen from,AnimatableScreen to) {
fromBmp = new Bitmap(Display.getWidth(), Display.getHeight());
toBmp = new Bitmap(Display.getWidth(), Display.getHeight());
Graphics fromGraphics = Graphics.create(fromBmp);
Graphics toGraphics = Graphics.create(toBmp);
Object eventLock = getApplication().getEventLock();
synchronized(eventLock) {
from.drawAnimationBitmap(fromGraphics);
to.drawAnimationBitmap(toGraphics);
// Interpolate myOffset to target
// Set animating = false if myOffset = target
invalidate();
}
try {
synchronized (Application.getEventLock()) {
Ui.getUiEngine().suspendPainting(true);
}
} catch (final Exception ex) {
}
}
protected void paint(Graphics g){
//control x,y positions of the bitmaps in the timer task and the paint will just paint where they go
g.drawBitmap(0,0, 360,
480, toBmp, 0, 0);
g.drawBitmap(0, 0, 360,
480, fromBmp, 0, 0);
// invalidate();
}
protected boolean touchEvent(TouchEvent event) {
if (!this.isFocus())
return true;
if (event.getEvent() == TouchEvent.CLICK) {
// invalidate();
}
return super.touchEvent(event);
}
}
Assuming you're working with version 5.0 or later of the OS, this page has a simple example:
http://docs.blackberry.com/en/developers/deliverables/11958/Screen_transitions_detailed_overview_806391_11.jsp
From where did you get the code sample posted in your question? That code does not appear to be close to working.
Update: you can actually animate transitions like this yourself fairly simply. Assuming you know how to use the Timer class, you basically have a class-level variable that stores the current x-position of your first Bitmap (the variable would have a value of 0 initially). In each timer tick, you subtract some amount from the x-position (however many pixels you want it to move each tick) and then call invalidate();.
In each call to the paint method, then, you just draw the first bitmap using the x-position variable for the call's x parameter, and draw the second bitmap using the x-position variable plus the width of the first bitmap. The resulting effect is to see the first bitmap slide off to the left while the second slides in from the right.
A caveat : Because this is java (which means the timer events are not real-time - they're not guaranteed to occur when you want them to), this animation will be kind of erratic and unsmooth. The best way to get smooth animation like this is to pre-render your animation cells (where each is a progressive combination of the two bitmaps you're transitioning between), so that in the paint method you're just drawing a single pre-rendered bitmap.

Hook for redraw event in Blackberry

Is there a way to add a redraw callback to a live screen object, i.e. not via inheritance?
Reasoning:
I want to draw an overlay from an extension for widget sdk (substituting jumpy position:fixed), so the screen is created by the bbwp stub.
I can get it by
Ui.getUiEngine().getActiveScreen()
and draw on it quite nicely, but I need a way to redraw when appropriate.
Note:
I've abandoned the approach to push the overlay as a screen, because i couldn't make it transparent / find a way to pass events through.
If you want to push the overlay as a screen, you should be able to make it's background transparent by overriding the paintBackground() method as follows:
// Make background transparent
protected void paintBackground(Graphics graphics) {
XYRect xy = graphics.getClippingRect();
graphics.pushContext(xy, 0, 0);
graphics.setGlobalAlpha(0);
graphics.setColor(0xffffff);
graphics.fillRect(xy.x, xy.y, xy.width, xy.height);
graphics.popContext();
}
Then, to pass touch events through, override the following method and return -1 if you don't want your screen to handle the touch event:
public int getFieldAtLocation(int x, int y) {
return -1;
}

Resources