Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Help about creating images inside classes

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to learn java for android -- after many years coding AS3 for flash.

I'm using Android studio.
I've gone through a bunch of tutorials but all of them either: Draw shapes/bitmaps directly in the main class OR Create references to a shape (Rect or something) in a secondary class then use a getRect command from the main class and THEN draw the image (but none have done this with a bitmap image so far) OR Use the xml layout tools and create no images through code at all.

Can someone explain to me (or point me in the direction of a tutorial) how I can create images inside subclasses (and what those classes would need to extend?)

I have a MainActivity class and a GameView class which I have copied from one of the tutorials I've done. I removed what the GameView was drawing, but kept everything else.
Instead I have it looking like this:


This works fine.



The above works fine, although I'm not sure if GridLayout is what I want to be extending. I think it is because after I make the tiles I want them to be arranged in the GridLayout position.



This class is the one giving me trouble.
First, I don't know what to extend. In AS3 I would extend Sprite and just do all my drawing right inside this object.
Second, I don't know how to draw from this class into the main view. Trying to get a bitmap like it currently is doesn't work because it doesn't see the resources.
I want each instance of "Tile" to have the view of my tile.png overlayed with a text field holding 'myChar'.
Then "TileHolder" should contain all those tiles (in a grid) to be displayed on the screen.

Again.. Can someone explain to me (or point me in the direction of a tutorial) how I can create images inside my Tile class to be displayed by my GameView class?
 
Marshal
Posts: 77531
372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I can never remember what to do with images, but have you tried the Java® Tutorials? There are several pages about images. I think that section is intended for Swing, so it might be different on Android.
 
A feeble attempt to tell you about our stuff that makes us money
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic