Jump to content
  • Advertisement
Sign in to follow this  
Kenneth Abuel

Hi! How do I create a character that will look like moving to the right

This topic is 708 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys! Out of my curiosity I started to learn Android, my current objective right now is to create a endless running game. So I already created a background scroll with background music which is nice, my objective right now is to put a character in the background scroll and make it look like running. I don't have idea how am I going to do it.


Here's my Game code:

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class GamePanel extends SurfaceView implements SurfaceHolder.Callback {

    public static final int WIDTH = 856;
    public static final int HEIGHT = 480;
    public static int Score = 0;
    public static int Highscore;
    private MainThread thread;
    private Background bg;

    public GamePanel(Context context) {
        thread = new MainThread(getHolder(), this);


    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {


    public void surfaceDestroyed(SurfaceHolder holder) {

        boolean retry = true;
        while (retry) {
            try {
            } catch (InterruptedException e) {
                retry = false;

    public void surfaceCreated(SurfaceHolder holder) {
        bg = new Background(BitmapFactory.decodeResource(getResources(), R.drawable.gamebg));
    public boolean onTouchEvent(MotionEvent event) {
        return super.onTouchEvent(event);
    public void update() {
        Score += 2;
        if (Score > Highscore) {
            Highscore = Score;

    public void draw(Canvas canvas) {
        final float scaleFactorX = (float)getWidth()/WIDTH;
        final float scaleFactorY = (float)getHeight()/HEIGHT;
        if(canvas !=null) {
            final int savedState = canvas.save();
            canvas.scale(scaleFactorX, scaleFactorY);


            Paint textpaint = new Paint();
            canvas.drawText("Score:" +String.valueOf(Score), 0, 32, textpaint);
            canvas.drawText("High Score: "+String.valueOf(Highscore), 0, 64, textpaint);


Am I going to create another class? or just put it on the game code?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!