Forum Replies Created
-
AuthorPosts
-
I often get a slowish first compile, but then it gets really fast (under 2 seconds) for subsequent changes/compiles, unless I make major changes that affect several source files. That’s about the same I was getting when changing Unity scripts.
I’m on a 2.5Ghz, quad core i7 Macbook.
Out of curiosity, how do you count all the lines of code in a lot of imported files?
<edit>
Figured it! Running this command line at the root directory of your project will do the trick.
find . -name “*.monkey2” | xargs wc -lTested, works here. Here’s a sample usage with a 5 frame 32×32 sprite (160×32 sprite sheet, no border or padding):
(requires previously posted LoadSpriteSheet function)[/crayon]Monkey1234567891011121314151617181920212223242526272829303132[crayon-5cba9a6934be0240063076 inline="true" ]#Import "<mojo>"#Import "<std>"#Import "images/testSprite.png"Using mojo..Using std..Class SpriteSheet Extends WindowField sprite:Image[]Method New()Super.New( "Test", 256, 256 )sprite = LoadSpriteSheet( "asset::testSprite.png", 5, 32, 32 )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.Clear( Color.Black )For Local n := 0 To 4canvas.DrawImage( sprite[n], n * 32, n * 32 )NextEndEndFunction Main()New AppInstanceNew SpriteSheet()App.Run()EndHere ya go:
Monkey123456789101112131415161718192021222324Function LoadSpriteSheet:Image[] ( path:String, numFrames:Int, cellWidth:Int, cellHeight:Int, filter:Bool = True, preScale:Float = 1.0, padding:Int = 0, border:Int = 0 )Local atlasTexture := Texture.Load( path, Null )Assert( atlasTexture, " ~n ~nGameGraphics: Image " + path + " not found.~n ~n" )Local imgs := New Image[ numFrames ]Local atlasImg := New Image( atlasTexture )If Not filter Then atlasImg.TextureFilter = TextureFilter.NearestLocal paddedWidth:= cellWidth + ( padding * 2 )Local paddedHeight:= cellHeight + ( padding * 2 )Local columns:Int = ( atlasImg.Width - border - border ) / paddedWidthFor Local i:= 0 Until numFramesLocal col := i Mod columnsLocal x := ( col * paddedWidth ) + padding + borderLocal y := ( ( i / columns ) * paddedHeight ) + padding + borderimgs[i] = New Image( atlasImg, New Recti( x , y, x + cellWidth, y + cellHeight ) )imgs[i].Scale = New Vec2f( preScale, preScale )NextatlasImg = NullReturn imgsEndThe “padding” and “border” arguments are designed to work with the way Aseprite exports sprite sheets. I haven’t tested this out of my framework, but it looks like it should work. Let me know.
I think I based this on some code someone posted on the Monkey-X forum. It’s been too long, can’t remember now…
Oh, and Hezkore’s icons look great! I love simple, monochrome icons.
Hi Nerobot,
Ted2Go looks great, and I’ve been wanting to use Ted or Ted2Go for a while, but I haven’t been able to yet, primarily because the text editing process itself is a bit jarring, since it doesn’t follow well established shortcut conventions on Mac OS. It would be incredible if it followed these conventions (same as Xcode or Sublime Text on MacOS):
File:
Command + W – Close tab (Should work now accoring to the menu, but doesn’t do anything on my machine)
Command + T – New Tab (Same as Command+N, New file)Text navigation:
Command + Right – Go to end of line
Command + Left – Go to beginning of line
Command + Up – Go to top of document
Command + down – Go to bottom of document
Alt + Right – Go to next word
Alt + Left – Go to previous word
(All of those should be combined with shift to perform selections, i.e. Shift+Alt+Right = Select next word)Build system:
Command + B – Build and run with current settings
Command + Shift + B – Just build
Command + R – Run last built appMiscellaneous:
Command + Shift + Z – Redo
Command + Comma – Preferences
Command + ForwardSlash – Toggle comments on/offNone of these are currently assigned or work correctly on my MacOS laptop. In addition, there are other minor things I noticed:
– Text cursor is almost invisible, very hard to find at a glance.
– Would it be hard to hilight the current line where the cursor is with a color slightly different from the background?
– Cursor is different in txt files and monkey2 files, is that intentional?
– A button in the toolbar to quickly toggle debug/release would be great!
– Indentation lines would be amazing! Here’s an attached example of how that looks like in Sublime Text 3.Thanks for this project! I’ll definitely drop some donation money once I can use it!
Cheers.Attachments:
<edit>
Never mind, works fine now. Thanks Mark!!!I agree that it needs to be “built-in”.
But for now, you can swap the icon without any extra software. If you already have the .icns file, simply right click the app, select “Show Package Contents”, navigate to the resources folder and drop the icon files there. Make sure it is named exactly like the executable file inside the MacOS folder, only with .icns extension instead.
One catch: usually MacOS won’t refresh the icon right away, even if you kill finder and relaunch. One quick way to check if it’s correct is to simply copy or move the app to a different folder, it should then display the updated icon.
I’m temporarily going back to creating the gameplay elements through code, like in the “Class Enemy” example in the original post.
Pros: Doable right now, and super easy to create instances (“New Enemy(x,y)”, etc.).
If I want to share the same instance of a component on all entities, I can simply make it a global in that new class. I tried instancing many entities sharing the same SpriteRenderer component, and it worked very well. Each entity passes its own state to the sprite renderer, which will draw different animation frames according to the current entity’s state.
Cons: Not very flexible from a game design perspective, can’t create new gameplay elements through a visual editor if those elements’ classes don’t already exist in code. Requires re-compiling every time a new class is added.
This attempt made me really appreciate all the under-the-hood effort that goes towards making game design easier in large engines like Unity, but at the same time I feel like I’m learning a lot.
I’ll try again in the future, for now I just want to move forward with what I have. Deep copying and Serialization would be great items to be included in Monkey2’s road map, with practical game development of complex projects in mind.
Cheers!
Thanks for the replies!
Out of curiosity, what’s missing from the current Reflection system? I’ve only dabbled in it, but it seems like you can access all fields from a class. Couldn’t a serializer be written with the current available features?
try using structs but as Mark suggests put the struct in another file (ideally on its own) why having its own “compilation unit” should help is just one of the “delights” of c++
I tried, still get the same compiler error. Also tried “New AppInstance” to make sure Image was initialized, no luck.
Yeah, this doesn’t even compile, so I think it’s something else. There’s no App.Run in this minimal example, but when I first ran into it I had a proper AppInstance.
The main thing I’d like to see in M2’s docs are very simple snippets/examples for all major classes, functions and language features. Searching the forum after “that example I remember someone posted a while ago” is frustrating, and will only get worse as more people post more often in the forums.
Once more content is in the docs, a better search system would also come in handy (the current one expands the tree view on the side for all results at the same time, resulting in lots of scrolling).
Thanks!
Thanks, that is helpful. This looks a bit more neat.
Monkey12345678910111213141516171819202122#Import "<std>"#Import "test.json"Using std..Function Main()Local data := JsonObject.Load( "asset::test.json" )If dataLocal clips := data.GetObject( "animationClips" )If clipsFor Local c := Eachin clips.ToObject()Local obj := c.Value.ToObject()Local loop := obj[ "loop" ].ToBool()Local rate := obj[ "rate" ].ToNumber()Local frames := obj[ "frames" ].ToArray()NextEndEndEndI had t add the line “Local obj := c.Value.ToObject()” which essentially casts the JsonValue as an object, so functionally it’s not that different, but it’s easier to read.
1.I’m trying to get rid of the casting. Is there a way to iterate the JsonObjects directly, instead of JsonValues? Which led me to…
2.I was wondering if there’s something wrong with JsonObject.All. I get an error when I try to use it instead of JsonObject.ToObject() (which returns a map)
Thanks.
This is really cool!
I still can’t wrap my head around GL shaders, though… the syntax is fine, but I can never understand how the stuff happening in the shader gets passed to the graphics card… like, are there pre-determined variables that do pre-determined things the driver expects that I’m supposed to use?Love the “sliced” graphics!
Not a fan of the rotated isometric controls. Would much prefer if “up” simply went up, instead of up/right in screen space. I know this is correct in relation to world space, but since the character moves in 8 directions I would have preferred more direct controls.
Can you give more details? Plain Monkey2, used existing libraries, etc.
Cheers! -
AuthorPosts
