my enemies vanished

Monkey Forums/Monkey Programming/my enemies vanished

Jeit(Posted 2012) [#1]
My enemies have completely vanished off of the face of my game. I was messing with Therevills code for pixel perfect sprite collision, attempting to make it work for the diddy sprite class and the player class I made. I honestly don't think that was the cause of the problem though. One moment they are there and working fine, the next they don't show up at all. They are created, debuglog tells me so, and I know the images are good since they still show up on the sidebar on the edit screen, they simply dont show up in the game window. So I promptly began removing bits and pieces of code I had added to see what caused it, nothing changed it. I reverted the entire game to a previous version that I know worked perfectly fine, they still aren't there. I have no idea what's going on. I have since made sure everything is updated, deleted the build folder, hell I even restarted windows in pure desperation. I don't know what else to try, any suggestions?


therevills(Posted 2012) [#2]
Are you using the latest version of Diddy? If so, you may need to set visible to true if you are not using the ctor.


Jeit(Posted 2012) [#3]
your a life saver, that was the problem. Thanks once again for your help. Though I am curious, what is ctor?


therevills(Posted 2012) [#4]
No problem... maybe we should default visible to be true...

Though I am curious, what is ctor?

Short hand for Constructor, the ctor for Sprite is:

[monkeycode]Method New(img:GameImage, x:Float, y:Float)
Self.image = img
Self.x = x
Self.y = y
Self.alpha = 1
Self.SetHitBox(-img.image.HandleX(), -img.image.HandleY(), img.w, img.h)
Self.visible = True
End[/monkeycode]


Jeit(Posted 2012) [#5]
ohhh, ok, thanks again.


therevills(Posted 2012) [#6]
How are you creating your sprites? And I've just defaulted visible to be true.


Jeit(Posted 2012) [#7]
I created a new class that extends sprite for my enemies, not much was added to your sprite class, I just needed a few extra bits of information when the enemy was created. On a side note, as I mentioned in the opening post, I'm trying to use your pixel perfect collision within the enemy class, and I believe I'm very nearly there, however I do not understand what exactly readPixels does. I get that it reads the pixels and imports the info into an array, however I'm not sure how I would tell it to read the pixels of a sprite sheet rather then straight from the gamescreen, if that's even what its doing >.<, jumping to definition on that one is a little less then helpful


NoOdle(Posted 2012) [#8]
You have a couple of options, images can be loaded, drawn to screen and then the pixels read into a created image. You can then modify and use this with the read/write pixel commands. To avoid having to draw the image to the screen and capture, you could write a simple program that exports the captured sprite sheet to a data file. Loading this image data file straight into a created image can then be done inside OnCreate of your app, bypassing the need to render and capture the sprite sheet.


therevills(Posted 2012) [#9]
We have been thinking about adding the read image stuff to Diddy and it shouldnt be too hard, its just on the first frame we would need to draw the images to the screen to capture the pixels.


Samah(Posted 2012) [#10]
its just on the first frame we would need to draw the images to the screen to capture the pixels.

Which wouldn't work for atlases that are bigger than the screen.


therevills(Posted 2012) [#11]
Okay, just added ReadPixelsArray to GameImage.


Jeit(Posted 2012) [#12]
Thanks for all the help everyone! Especially thank you therevills, you just made this a whole lot easier.


therevills(Posted 2012) [#13]
No problem, does it make sense on how to use it?


Jeit(Posted 2012) [#14]
Through trial and error I'm getting closer and closer to being able to use it. I had thought it would read the entire sprite atlas at first, loading it in as an animated image though, it only reads one frame at a time. Tried to have it read the sprite's image every time the frame changed, and that didn't work since that image kept appearing in the center of the map surrounded by black for a sec. Currently trying to get it to read the entire sprite atlas again as the program first begins and running into difficulties with loading an animated version and a not animated version of the same atlas, and then difficulties loading the not animated version, having it read that image, then switch the image over to the animated version.


therevills(Posted 2012) [#15]
I've updated the SpriteAtlas demo to show you how I would use it.

http://code.google.com/p/diddy/source/browse/trunk/examples/SpriteAtlas/spriteAtlas.monkey?spec=svn494&r=494

Basically:
[monkeycode]Class MyGame Extends DiddyApp
...
' 4th parameter = readPixels, so all sprites in the atlas will have their pixels read
images.LoadAtlas("sprites.xml", images.SPARROW_ATLAS, True, True)[/monkeycode]

[monkeycode]Class GameScreen Extends Screen
Field readComplete:Bool = False
...
Method Render:Void()
' read the pixels on the first frame
If Not readComplete
game.images.ReadPixelsArray()
readComplete = True
End
' normal game rendering
Cls
...[/monkeycode]

So now you can get the pixels from each of the images in the atlas like this:
[monkeycode]Local gi:GameImage = game.images.Find("longsword")
Print "Pixels length = "+gi.Pixels.Length()[/monkeycode]
In the SpriteAtlas example I actually create a new image with the pixels array.

Hope this helps.


Jeit(Posted 2012) [#16]
I am having so much trouble with read pixel array. First question, in the sprite atlas example, why does it work for Find("Axe") and Find("longsword") but it doesn't for any of the other images? For my second question I'm going to do my best to paste all relevant code.


I think that's everything outside of the player's getpixel, which is much the same except more images depending on what the player is doing. So my question is, what am I doing wrong? When I did debuglog on a1 in spritecollide all it showed were a few thousand 0's. And if there is any further code I missed or you want to see, let me know, I have hit a brick wall on getting this to work.