Drawing with bitmap

Problems with Canvas, OpenGL, etc...

Drawing with bitmap

Postby Cursey » Tue Jul 13, 2010 10:00 pm

Hello there, I'm trying to code a simple pong game and the only problem I seem to be running into is when I try to draw the items it always seems to be directing me to some randomly generated file instead of the drawable directory. I'm new to programming so you might have to talk to me like a kid :) .I'm taking from the example of the LunarLander sample. Thanks!
Code: Select all
Resources res = gContext.getResources();
         
          gBall = context.getResources().getDrawable(
                    R.drawable.ball);
         gBar = context.getResources().getDrawable(
               R.drawable.bar);
         
         gBackground = BitmapFactory.decodeResource(res,
               R.drawable.pics.background);
         
         gPongWidth = gBar.getIntrinsicWidth();
            gPongHeight = gBar.getIntrinsicHeight();
Cursey
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Jul 13, 2010 9:52 pm

Top

Re: Drawing with bitmap

Postby Ennan » Mon Jul 19, 2010 3:11 pm

Maybe i don't understand the question, but here goes:

I don't know what gContext and context are, but you have a Resource "res" from gContext, and get the drawables from 'context' ?

So if we make this a really simple case, lets say you only have one activity, and this is all done in the onCreate of that activity, you should be able to do this:
* you have a file "myfile.png" in your drawable dir
* call
Code: Select all
Drawable d = getResources().getDrawable(R.drawable.myfile);
//do something with d. like draw it on the canvas

* ....
* profit!
Ennan
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Aug 30, 2009 2:38 pm

Re: Drawing with bitmap

Postby chris.tucket » Sat Jul 24, 2010 5:12 pm

Is the "randomly generated file" from when you're debugging? If so, that is usually because there is an error in your code.
chris.tucket
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sat Apr 17, 2010 6:19 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest