Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Bitmap only drawn once not drawn in updated co ordinates

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 VIJAY007   Members   

107
Like
0Likes
Like

Posted 11 December 2012 - 01:20 AM

Hi all

am trying to draw bitmap and redraw it in updated coorinates.but it is only drawn once.
what to do.

Code for your reference.
MainActivity.java

import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.app.Activity;
import android.view.Display;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;
public class MainActivity extends Activity {
private PowerManager mPowerManager;
//private WindowManager mWindowManager;
//private Display mDisplay;
private WakeLock mWakeLock;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new BitmapView(this));
// Get an instance of the PowerManager
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
// Create a bright wake lock
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass()
.getName());
}

@Override
protected void onResume() {
super.onResume();
/*
* when the activity is resumed, we acquire a wake-lock so that the
* screen stays on, since the user will likely not be fiddling with the
* screen or buttons.
*/

// Start the simulation

}
@Override
protected void onPause() {
super.onPause();
/*
* When the activity is paused, we make sure to stop the simulation,
* release our sensor resources and wake locks
*/
// Stop the simulation
// mSimulationView.stopSimulation();
// and release our wake-lock
//mWakeLock.release();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

BitmapView.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;
class BitmapView extends View {
int posx=10;
int posy=10;
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.obstacle);

public BitmapView(Context context) {
super(context);
}
public void update()
{


if(posx>getWidth())
{
posx=-17;
}
else
{
posx=+17;
}

}
@Override
public void onDraw(Canvas canvas)
{
//super.onDraw(canvas);
canvas.drawBitmap(bmp, posx, posy, null);
update();
invalidate();

}




}




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.