Can't see canvas unless I resize emulator

24 views
Skip to first unread message

Gareth Murfin

unread,
Jul 25, 2016, 8:13:48 AM7/25/16
to CodenameOne Discussions
I am trying to port an old arcade game to codename one. I am using the canvas and have something drawing, but I can only see it when Im literally resizing the emulator window, other than that it is white. Any ideas?? 

Here is how I add my game to a form and keep it repainting:

Form f = new Form("");
            f.setLayout(new BorderLayout());      
            DDragon game = new DDragon(null, new DDApp());     
            f.add(BorderLayout.CENTER,game);
        
            new UITimer(new Runnable() {
              public void run()
              {              
                  if (game!=null)
                  {
                       game.run();
                       game.repaint();
                  }
                  else
                  {
                      System.out.println("game still null");
                  }              
               }
           }).schedule(10, true, f);         
            f.show();

Gareth Murfin

unread,
Jul 25, 2016, 8:21:32 AM7/25/16
to CodenameOne Discussions
ps DDragon extends Component and has an override for paintBackground

Gareth Murfin

unread,
Jul 25, 2016, 9:02:21 AM7/25/16
to CodenameOne Discussions
Fixed it, it was my own canvas logic. Also curious if there are any libs around with things like drawRegion in the graphics class? And Sprite stuff from old midp2 days and things for flipping sprites in code (TRANS_MIRROR)

Gareth Murfin

unread,
Jul 25, 2016, 10:17:59 AM7/25/16
to CodenameOne Discussions
Also interested in anyway to mimic "anchors" when doing a drawImage(), im basically porting old j2me canvas titles.

Gareth Murfin

unread,
Jul 25, 2016, 10:29:24 AM7/25/16
to CodenameOne Discussions
And I need graphics.copyArea() :-) looks like im gonna have to implement some of these... got the port of the game working actually, its only the flipped sprites missing!

Gareth Murfin

unread,
Jul 25, 2016, 11:34:21 AM7/25/16
to CodenameOne Discussions
OK looks like img.mirror() and img.subImage() can copy these functions well! So all working now.

ie, J2ME:

 gs.drawRegion(img, 
               rgRect[0], rgRect[1], rgRect[2], rgRect[3],
               Sprite.TRANS_MIRROR,
               posx-rgRect[4], posy-rgRect[5],
               Graphics.LEFT | Graphics.TOP );

can be done in cn1 as:

 img=img.subImage(rgRect[0], rgRect[1], rgRect[2], rgRect[3],true);
        img=img.mirror();
        gs.drawImage(img, posx-rgRect[4], posy-rgRect[5]);

Awesome.
Reply all
Reply to author
Forward
0 new messages