Welcome, Guest |
You have to register before you can post on our site.
|
|
|
Simple SpriteSheet Editor step by step in QB64pe |
Posted by: TempodiBasic - 06-04-2023, 05:04 PM - Forum: Works in Progress
- Replies (5)
|
|
Hi
this is a first version of a SpriteSheet editor: a program that loads a SpriteSheet and let you modify it painting with simple tools or/and lets to select an area as a single sprite into the sheet. After selected the sprites, you can save their cohordinates into a DATA file to use into your code with the original SpriteSheet and you can see the selected sprite shown on the screen.
It is a project step by step:
this first step brings a program with a main window that will be adapted to the spritesheet loaded and on this the user can define the 2 points to select an area of the picture to do a single sprite. You can accept/store or cancel each point selected before, after stored point 1 and 2 you get the sprite that is highlighted by a red square.
You can stop the selecting function pressing spacebar into the main loop or mousebutton2 while you are selecting the point 2.
the selected sprites will be displayed at the end of the procedure of selection.
This program uses a second area /canvas to give output to the user as messages or warnings or instructions.
I have posted some screenshots.
It is really incomplete but it can grow up if I use Option _explicit avoiding to waste so much time with bugs going out from my typo errors!
Code: (Select All) Option _Explicit
Rem SPRITE SHEET EDITOR
Rem this software has the purpouse to load an image of a sprite sheet
Rem and in SELECT MODE it allows to the user to select an area,
Rem or in EDIT MODE to paint changing the images into the sprite sheet
_Title "SpriteSheet Editor"
Const W = 1200, H = 800
'global varables
Dim Shared Main&, Sprite&, NameFile$, SSheet&, HelpS&
ReDim Sprites&(1 To 1)
Dim Shared As Integer Xm(1 To 2), Ym(1 To 2), SprC(1 To 4, 1 To 100)
' main variables
Dim Mg As Integer, a As Integer, Mb1 As Integer, Mb2 As Integer, kb As Integer, spr As Integer
Main& = _NewImage(W, H, 32)
HelpS& = _NewImage(W, H / 4, 32)
Screen Main&
_PrintString ((W / 2) - (10 * 8), H / 2), "SPRITES SHEET EDITOR" ' the title is 20 characters
_Delay 3
_SetAlpha 125, HelpS& ' area of output is half transparent
LoadI
Mg = 13: a = 0 'Mg pixel between 2 lines of the reticulus, a is a counter
While kb <> 32 ' while user does not press spacebar, he can define area on the screen delimiting sprites to capture into single area/canvas
Helping " Press spacebar to end", 1
If MouseData(Mb1, Mb2) = -1 Then 'it evaluates mouseinput
If Mb1 Then 'did mouse button 1 trigger?
' it starts the procedure for storing X an Y of points 1 (topleft) and 2 (bottomright)
If StoreMouseData(1) = -1 Then ' it stores mouse data for topleft point of sprite
While 1
Helping " Press spacebar to end", 1
Helping Str$(_MouseX) + Str$(_MouseY) + Space$(8), 0
'_Dest HelpS&: Locate 4, 26: Print kb; Space$(10);
'Locate 5, 1: Print _MouseX, _MouseY; Space$(8);: _Dest 0
'_PutImage (0, 2 * (_Height(0))), HelpS&,
If MouseData(Mb1, Mb2) = -1 Then ' it evaluates mouse input
Helping " Press spacebar to end", 1
Helping Str$(_MouseX) + Str$(_MouseY) + Space$(8), 0
' it adjourns the keyboard and mouse information
'_Dest HelpS&: Locate 4, 26: Print kb; Space$(10);
'Locate 5, 1: Print _MouseX, _MouseY; Space$(8);: _Dest 0
'_PutImage (0, 2 * (_Height(0))), HelpS&,
If Mb1 Then 'did mousebutton 1 trigger?
If StoreMouseData(2) = -1 Then ' yes, it stores mouse data bottomright
' after confirming the two points of the sprite it memorizes their cohordinates into SprC array
spr = spr + 1 ' sprite counter
SprC(1, spr) = Xm(1): Xm(1) = 0 'X1
SprC(2, spr) = Ym(1): Ym(1) = 0 'Y1
SprC(3, spr) = Xm(2): Xm(2) = 0 'X2
SprC(4, spr) = Ym(2): Ym(2) = 0 'Y2
Line (SprC(1, spr), SprC(2, spr))-(SprC(3, spr), SprC(4, spr)), _RGB32(233, 0, 6), B
Helping Str$(spr) + "/" + Str$(SprC(1, spr)) + "+" + Str$(SprC(2, spr)) + "--" + Str$(SprC(3, spr)) + "+" + Str$(SprC(4, spr)), 0
_Delay 1
Exit While ' after storing point 2 of sprite it returns to external loop
Else
Helping "To exit press mouse button 2", 0
_Delay 2
End If
End If
If Mb2 = -1 Then Exit While
End If
Wend
End If
' if no data stored for point 1 topleft it runs again the loop
End If
End If
kb = _KeyHit
' escaping way
If kb = 13 Then Grid
Helping Str$(kb), 0
Helping Str$(_MouseX) + Str$(_MouseY), 0
While _MouseInput: Wend ' it voids the mouse buffer
_Limit 10
Wend
Screen Main&
Helping "Save data of sprites into a DATA code file (Y/N)?", 1
kb = 0
While kb = 0
kb = _KeyHit
If kb = 89 Or kb = 121 Then SaveDATAtoFile: Exit While 'Y or y
If kb = 78 Or kb = 110 Then Exit While ' N or n
kb = 0
Wend
' getting single sprites with newimage
ReDim Sprites&(1 To spr), x As Integer, y As Integer
For a = 1 To spr
Sprites&(a) = _NewImage(Abs(SprC(1, a) - SprC(3, a)), Abs(SprC(2, a) - SprC(4, a)), 32)
_PutImage , Sprite&, Sprites&(a), (SprC(1, a), SprC(2, a))-(SprC(3, a), SprC(4, a)) 'it copies area of spritesheet to single area/canvas
x = x + _Width(Sprites&(a)) ' it adjourns the cohordinates X for showing sprites in sequence
y = _Height(Sprites&(a))
_PutImage (x, y), Sprites&(a), 0 ' showing sprites from 1 to top
Next a
End
Sub SaveDATAtoFile
Rem Saveto DATA file
Rem save to file in DATA format the array SprC
Dim n As Integer
Open "Datafile.txt" For Output As #1
Helping "Saving data...", 0
Print #1, "Data";
For n = 1 To 100 Step 1
If SprC(1, n) = 0 Then _Continue ' if it finds a wrong value it exits from FOR loop
If (n Mod 9) = 0 Then Print #1,: Print #1, "Data"; Else If n > 1 Then Print #1, ",";
Print #1, SprC(1, n), ",", SprC(2, n), ",", SprC(3, n), ",", SprC(4, n);
Next
Close #1
Helping "Saved data!", 1
End Sub
Function MouseData (Mb1 As Integer, Mb2 As Integer)
MouseData = 0
While _MouseInput: Wend ' it waits that mouse input ends
Mb1 = _MouseButton(1)
Mb2 = _MouseButton(2)
If Mb1 <> 0 Or Mb2 <> 0 Then MouseData = -1 ' if no mousebutton then function returns failure
End Function
Function StoreMouseData (Index As Integer)
Dim kb As Integer, OldC As Long
StoreMouseData = 0
If _MouseX > 0 Then Xm(Index) = _MouseX Else Xm(Index) = 1 ' it corrects wrong 0 values
If _MouseY > 0 Then Ym(Index) = _MouseY Else Ym(Index) = 1
If Xm(Index) > 0 And Ym(Index) > 0 Then
' both cohordinates are good?
Helping "Storing point " + Str$(Index) + Str$(Xm(Index)) + "-" + Str$(Ym(Index)) + " Cancel/Store?", 0
OldC = Point(Xm(Index), Ym(Index))
PSet (Xm(Index), Ym(Index)), _RGB32(211, 255, 6)
While 1 'kb <> 83 Or kb <> 115
' here the loop to take cancel/store data
kb = _KeyHit
If kb = 67 Or kb = 99 Then
PSet (Xm(Index), Ym(Index)), OldC
Exit Function ' if key is c or C then exit function returning the failure
End If
If kb = 83 Or kb = 115 Then Exit While
Wend
Helping "Stored", 0
_Delay 1
StoreMouseData = -1
Else
Exit Function
End If
End Function
Sub Grid
Shared Mg As Integer, a As Integer
For a = 1 To W Step Mg
Line (a, 1)-(a, W), Mg
Next
For a = 1 To H Step Mg
Line (1, a)-(H, a), Mg
Next
End Sub
Sub LoadI
NameFile$ = ".\defendersprites.jpg" '<----- coming soon Open option to type name of file and better an Opendialog box
If _FileExists(NameFile$) Then
Helping "File founded", 1
Sprite& = _LoadImage(NameFile$)
Else
Helping "Error: image not loaded", 1
Sprite& = -1000 ' sprite& brings the failure flag
_Delay 2
Exit Sub
End If
_Delay 1
SSheet& = _NewImage(_Width(Sprite&), _Height(Sprite&), 32)
Screen SSheet&
_PutImage , Sprite&, 0
End Sub
Sub PaletteS
Dim n As Integer
For n = 1 To 256
'pset (n,1),n
Line (n, 1)-(n, 256), n, BF
Next n
Sleep 2
End Sub
Sub Helping (Msg As String, M As Integer)
_Dest HelpS&
If M = 1 Then Cls
Print Msg
_Dest 0
_PutImage (0, 2 * (_Height(0) / 3)), HelpS&,
End Sub
Welcome feedbacks and propositive criticisms.
I'm thinking to add a third way to select the area with a dragging of mouse like in the graphic editor in which you draw a square/rectangle.
Moreover I need an OpenDialog box to choose the file of the Spritesheet to modify. I think that the created/selected sprites must be managed like in a list box with a single/multiple selection for doing specific actions (Save, Cancel, Edit...).
I have never used a SpriteSheet Editor but I'm doing it from zero with poor plan... this will cause so much modifications! Sob. Better measures twice and cut ones.
this is the spritesheet that I have used as file, but use whatever do you want
|
|
|
Option _Explicit Keyword(s) of day XXX: |
Posted by: bplus - 06-04-2023, 04:29 PM - Forum: Keyword of the Day!
- Replies (27)
|
|
This thread started so people can talk about Option _Explicit without hijacking other threads.
Use Option _Explicit in your code to save yourself from typos, probably the number one cause of grief to any coder on any level.
Yes it forces you to declare every variable you use. Yes Dimster that includes For ... Next index variables.
If declared variable is a Const, you don't have to DIM it, same goes for Static, same goes for ReDim (or should).
But there is an interesting by-pass, if I recall, stay tuned... Nope! the example I had in mind didn't work as I remembered.
|
|
|
QB64PE Programs being flagged as having trojans |
Posted by: hanness - 06-04-2023, 02:30 AM - Forum: General Discussion
- Replies (7)
|
|
I have multiple programs that I have written in QB64PE that get flagged by Windows Defender on Windows 11 as having trojan malware.
For now I've been setting exceptions in the antivirus software, but I'm wondering if there is any other kind of strategy to avoiding this in the future.
|
|
|
Welcome grymmjack as Forum Guru! |
Posted by: SMcNeill - 06-03-2023, 06:53 PM - Forum: General Discussion
- Replies (12)
|
|
Everyone give a big hand of applause and many thanks to grymm for volunteering to step up and help with our server and forum maintenance and usability. Pete was helping me with these things, but he's wandered off into the sunset after all the flooding his area of the world got since last December, and nobody's heard from him since. (Let's all pray he's good and just dealing with insurance issues and such and simply hasn't felt like being indoors or programming for a while, and that nothing bad happened to him.)
Grymm's taken over handling our back-end server maintenance, and it's all thanks to him and @dbox that we can now embed QBJS in posts here and run those programs and examples. He's currently at work on integrating our forum notifications so they appear in Discord for us, and who knows what improvements, optimizations, and fixes he'll bring in the future! (After all, he's only been on the job for all of 2 days now, I think, and he's already finished the QBJS iFrame stuff!)
Any suggestions, issues, fixes, kindly @grymmjack with your concerns, and be certain to thank him for all his hard work and efforts. Like everyone else who contributes to this project, grymm is doing so of his own free will and in his own free time, with no pay or reimbursement for his work. Let him know if there's something he might can look into and help with, but as always -- be respectful and don't expect things to change instantly just cause someone reported something or requested something. He's got a life, and he's got a right to live it first and foremost -- like any other dev here -- and even moreso, he now has admin rights and can ban those who are too pestersome for him....
|
|
|
BAM thingies in the works |
Posted by: CharlieJV - 06-03-2023, 03:36 AM - Forum: QBJS, BAM, and Other BASICs
- Replies (19)
|
|
Currently in the works (click here for details; click here to try the test version of BASIC Anywhere Machine)
- Documentation: setup the architectural components for syntax diagrams, and start using/testing syntax diagrams with the statements/functions/operators below
- Enhanced debugging: added generic code issue notification and viewing mechanism, and specific catching missing definitions for SUB and FUNCTION declarations
- Added UrlQueryString$ function
- Added UrlKey$ function
- Added IFF function
- Added MIN and MAX functions
- Added BIN$ keyword (alternative name for already existing _BIN$ function)
- Added DAY$ function
- Added DIV keyword (alternative for the already existing "\", i.e. integer division, operator)
- Added FRAC function
- Added BETWEEN function
- Added CHOOSE function
- Enhanced compatibility of DEFtype statements
- Enhanced compatibility of _BIN$, HEX$, OCT$ functions
- Enhanced compatibility of SLEEP statement
- Enhanced compatibility of INSTR function
- Enhanced compatibility of RANDOMIZE function
- Enhanced compatibility of INTEGER data type
- Fixed the WIDTH statement: fixed a little glitch and documented behaviour
- Added the HEIGHT statement (WIDTH specifying the number of text columns, why not be able to specify the number of rows?)
- Added PUTSTRING statement
- Added SCROLL statement
|
|
|
On Exit question |
Posted by: NasaCow - 06-02-2023, 03:50 AM - Forum: Help Me!
- Replies (52)
|
|
I am trying to control exiting to prevent work from getting loss and adding some basic code related to EXIT is having my program crash out with Error 10 - Duplicate definition (The error points to the label ShutDown). I tried to step through it to see how the program flows exactly but with no success. Is running the timer all the time to check a bad idea for complex programs? Getting it to work with a simple loop seems to be no problem, inserting into Grade Keeper seems to be breaking something...
Quote:'Disabling the default exit routinue
ExitFlag = EXIT
ON TIMER(1) GOSUB ShutDown
TIMER ON
...
ShutDown:
ExitFlag = EXIT
IF ExitFlag THEN SYSTEM
RETURN
|
|
|
|