Am I caught by Sprite.Value again?

enonod

Well-Known Member
Licensed User
Longtime User
I have in an add sprites sub...
B4X:
For j=0 To 19
   Pawn.New2(AppPath & "\PSprite.png",6,15,15,6)
   Pawn.Data=1
   Pawn.Data=bit.ShiftLeft(Pawn.Data, j Mod 3)
   Pawn.X = 1
   Pawn.Y = i*16+1
   Pawn.Velocity = 0
   Pawn.Direction = 0
   gw.SpriteAdd(Pawn.Value)   
Next
Line 4 gives me an error... Object reference not set to an instance...
Pawn object exists properly.
My brain just isn't coping with something in this regard.
 

agraham

Expert
Licensed User
Longtime User
B4X:
Pawn.New2(AppPath & "\PSprite.png",6,15,15,6)
You will save a lot more data using a "stock" Pawn and using New4 to share the Bitmap array than you will use up with all those "constants". That loop allocates a minimum of over 81Kbytes of bitmap pixel data not including class structure overheads.
B4X:
Pawn.Data=1
Pawn.Data=bit.ShiftLeft(Pawn.Data, j Mod 3)
Why not "Pawn.Data=bit.ShiftLeft(1, j Mod 3)"?

The code looks OK, have you "New1"ed bit?
 

enonod

Well-Known Member
Licensed User
Longtime User
Well now, as I see it...
1 you just added new4 to the Sprite Help while I was reading your answer
2 I didn't study the Help carefully enough and probably would have missed it anyway
3 same again, I didn't scroll the Help and didn't realise it was an Object.

I have seem to have difficulty in forgetting the past. There is much subtlety to this B4PPC.
Thank you for all and sorry to have wasted your time.
[Edit] I would be grateful for a pointer to an example using New4 if possible
 
Last edited:

agraham

Expert
Licensed User
Longtime User
I would be grateful for a pointer to an example using New4 if possible
This modified version of the Sprite example uses it. I'll ship this to Erel with the other stuff when I'm finally happy with the state of the library.
 

Attachments

  • SpritesNew.sbp
    6.1 KB · Views: 168

enonod

Well-Known Member
Licensed User
Longtime User
I couldn't quite make the leap regarding from another sprite, which I now see can be a dummy.
All is now clear, thank you for that example.
 
Top