1
\$\begingroup\$

I've set app view on XML based layout:

setContentView(R.layout.mlayout);

with some views objects on it. Then, I added another view via:

RelativeLayout layout = (RelativeLayout) findViewById(R.id.game);
layout.addView(new GamePanel(this));

Where GamePanel class head looks like this:

public class GamePanel extends SurfaceView implements SurfaceHolder.Callback

I've created a view object programmatically in GamePanel class, and tried to set it's X to its pos.X + 1 on each update. From logcat, the X is really changing to X+1 on each update, but on mobile screen the object is still on the same place (it didn't moved nor a bit; it's still on the place where it was placed first during creating). Why it doesn't move?

Draw method in GamePanel:

@Override
    public void draw(Canvas canvas)
    {
        if (canvas!=null)
        {
            final int savedState = canvas.save();

            if (objects != null)
            {
                for (Object o: objects)
                {
                    o.draw(canvas); 
                }
            } 
            canvas.restoreToCount(savedState);
        }
\$\endgroup\$
1
  • \$\begingroup\$ Do you have a thread running that updates your surfaceview? \$\endgroup\$
    – ElDuderino
    May 10, 2016 at 7:42

1 Answer 1

1
\$\begingroup\$

I am not exactly sure what your problem is. Did you place the pos.X + 1 in the proper place. Could you edit to show the object? Then maybe your problem could be solved. For a start, you should check where you placed all your objects and everything. That is were the errors usually come.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .