Chess piece on view
No ok, I've found my copy error, Now I will check
This works, but you need to define an ImageView as subview of your custom views
It should be better if your boxes were buttons instead of ui.views and fill their background_image
def __init__(self): self.touch_enabled = True iv = ui.ImageView() iv.frame = self.bounds iv.image = ui.Image.named('emj:Angry') #iv.load_from_url('https://image.flaticon.com/icons/png/128/36/36189.png') self.add_subview(iv) def did_load(self): pass
It would be easier to create your 64 views by program, rather than by the ui designer.
Quick and dirty script, only to show, try it please
import ui def baction(sender): sender.superview.name = sender.name v = ui.View() v.background_color = 'white' y = 10 d = 40 for row in range(8): x = 10 for col in range(8): b = ui.Button() b.name = 'row '+str(1+row) + ' / ' + 'col '+str(1+col) b.frame = (x,y,d,d) b.background_image = ui.Image.named('emj:Airplane') b.action = baction v.add_subview(b) x = x + d + 10 y = y + d + 10 v.present()
Ok, I’m going to do some stuff about it and if I get a problem I will come back another day I guess.
Just to show how it could be easy
import ui def baction(sender): sender.superview.name = str(sender.row_col) v = ui.View() v.background_color = 'white' v.name = 'for @AZOM' pieces = ['♜♞♝♛♚♝♞♜','♖♘♗♕♔♗♘♖'] y = 10 d = 50 flip = 0 for row in range(1,9): x = 10 for col in range(1,9): b = ui.Button() b.font = ('<System>',d*0.8) b.tint_color = 'black' b.border_width = 1 b.row_col = (row,col) b.frame = (x,y,d,d) if row == 1: b.title = pieces[row-1][col-1] b.tint_color = 'black' elif row == 2: b.title = '♟️' elif row == 8: b.title = pieces[row-7][col-1] elif row == 7: b.title = '♙' b.background_color = ['beige','brown'][flip] b.action = baction v.add_subview(b) flip = 1 - flip x = x + d + 2 flip = 1 - flip y = y + d + 2 v.present()
You might consider scene instead of UI. Scene would let you animate the piece motions more naturally for example.
@JonB you right, of course, but I only wanted to show it is easier to create the buttons by program instead of the ui designer
And that you don't need images for the chess pieces, because there are ucode characters representing them
I was trying to run scripter-demo.py, but I got:
scripter/init.py", line 63
except Usage, err:
SyntaxError: invalid syntax
My fault - wrong installation procedure.