Tiled Game Background and the "'float' object cannot be interpreted as an integer" error - pygame

I am working my way through an entry level Pygame tutorial on a Windows 7 machine and for the following code, I am getting this error:
"builtins.TypeError: 'float' object cannot be interpreted as an integer"
# 6 - Draw the screen elements
for x in range(width//grass.get_width()+1):
for y in range(height//grass.get_height()+1):
screen.blit(castle,(0,30))
Through my research on this site I found that using the int division separator (//) got me past the error, but alas my grass image won't tile. I know this code works with (/) on my Linux machine because I have completed the game previously. If you take the time to look into this I truly appreciate your help! :-)

Well it seems that the problem is because in your loop you are bliting a castle, and not a grass tile.
this should fix it:
screen.blit(grass,(x*grass.get_width(),y*grass.get_height())

Related

AS3 - Moving a clip (player) along a path

I'll try to explain my problem in a clear and short way.
I'm writing a grid-game. In this game when the player clicks somewhere, the player moves, along the grid with a path calculated by the computer (because there's obstacles that the player avoid : walls...) to the final point.
It's an isometric grid but it's like it was a basic 2D grid.
So I have my path, which is a Point Array (key points screen coordinates) :
path : [x=10,y=100],[x=40,y=172], .. etc.
To display the movement of the player, I tried to use tweens (TweenLite/TweenMax).
There's no option on TweenLite to wait for a tween to finish before starting the next. In any case the solutions seem complicated (shitty delays/onFinish:function).
The solution I found is acceptable : TweenLite provides a LinePath2D function which works exactly like I wished. The only problem is that it works with only one function (path is the complete array):
var pathanimate:LinePath2D = new LinePath2D(path);
pathanimate.addFollower(Player);
TweenMax.to(pathanimate, 1, { progress:1, ease:Linear.easeNone });
So I can't "touch" anything during the movement. INCLUDING the aspect of the sprite of the player that must changes with the direction during each step of the path (it would be more simple if it LinePath worked with a loop).
I don't know if this is clear (i'm french huh) but I see only but two options :
Keep the LinePath and have, on each frame, some kind of counter/timer that "measures" the direction of the player. Could be heavy in ressources, but keeps the LinePath2D that works very well alone
Find another solution
I'd be glad to hear your ideas and code !
Thanks in advance
Actually I can provide several solutions, but they will include many lines of code. Briefly speaking:
System of waypoints. You have algorithm to set collection of waypoints to your character, and render him (updating from the main gaming loop), and character reaches one waypoint after another by shifting them from the collection.
Working with tweens, append them (so there will be queue).
In both options, you can set new path for the character, all you need is simple logic to approximate current position of the character to the closest grid point, and calculate new path from there, It's very easy with basic grid systems, like:
closestGridCellX = Math.round(this.x / gridCellSize);
closestGridCellY = Math.round(this.y / gridCellSize);

Flash Pro: Collision of objects only works correctly when on Frame 1

as you may have noticed just by reading the title it is quite hard to summarize the problem,
which is probably why I couldn't find a solution anywhere.
I am currently working on a flash game using adobe flash pro CC.
I started by creating the first level of my sidescrolling game and got everything to work just as I wanted it to. All my work was on a single frame (frame 1) and on a single layer and it worked fine.
However, when I then went on to move the frame a little further back and added frames in front of it for the menu I encountered a problem.
When I "gotoAndStop" to the frame with my game content on it, everything works except the collision between my character and my objects. My character is now sunk into the "floor object" about have his size, while when i move the frame back to "frame 1" everything works fine again.
I am losing my mind over this. Please help me :(
in flash when you start changing a dynamic property such as x or y, that object will be independent from the keyframe where it originally was ~forever~, even if you go back to the original keyframe. therefore if you start some enterframe and change the playhead afterwards you will get some awkward (but expected) behaviour.
ideally, jump to the game keyframe and just then call whatever methods needed to start the game.

addFrameScript does not work correctly with Air 2.6

I have coded two programs using flash cs5.5. Both of them use addFrameScript to organize the code on each frame.
The first one I exported on Air For Android and had no problem with it.
The second one I exported on Air 2.6 and a problem occurred.
If I go from frame to frame in order (using gotoAndStop()) then frame script loads perfectly.
But when I use the same method (gotoAndStop()) to go back to a previous frame, all of the stage instances on my lower layers are not loaded properly so I get ERROR 1009: Cannot access a property or method of a null object reference
Funny thing, when I move them up to the first two layers, things start working again.
But I still want to keep them in their own layers. Some help please?
Thanks in advance
EDIT 1:
I just found out that if move them up to a new layer then the older elements in that layer will not be loaded properly. It's like only the first few children of the display list are loaded.
EDIT 2:
If I change it to Air For Android, the problem disappears !! my mind is blowing right now

Uncertainty about the term "image lable file" (ITK)

I've been using ITK recently and I'm not really skillful on it, so I
apologize if my question seems childish !
here is the question: I've built a couple of ITK Examples on my machine (Win
7 x64) successfully and then tried to run an example to test the result, as
I was interested to watershed segmentation I tried it (WS3D), but except the
input and output image files which has to be defined, then it needs an
additional parameter to be defined called : LabelImageFile, exactly like
this :
WS3D InputImageFile LabelImageFile OutputImageFile
And unfortunately I have no idea what is LabelImageFile, how can I obtain a
Label Image for a specific image ?I'd be so much grateful if anyone can help
me, many thanks in advance,
Shawn
The watershed segmentation algorithm looks for a function f that is a continuous height function defined over an image domain. Such that a catchment basin is defined as the set of points whose paths of steepest descent terminate at the same local minimum of f. This catchment basin is your watershed result.
The label image that the filter is expecting is the function f or the height function. You can generate one such image by applying gradient magnitude to the original image.

What Windows "Performance monitor" settings should I use to debug a Flash movie that throws an InvalidBitmap error?

Here's my problem:
I have a Flash swf that uploads files from local machine and if they are images it resizes them if needed. This involves creating a JPGEncoded bytearray from a bitmapData object. After im finished with the bitmapData I dispose() of it.
I am noticing that flash will get stuck while resizing an image sometimes and have tracked this down to an "invalid bitmapData" error message. I tried last night before leaving work and it was throwing this message after 2 images!! This morning it all seemed to be fine so I decided to push it and tried uploading 20 images of 5616x3744 pixels and 5.32MB (the same images I tried previously).
I switched on performance monitor in windows and started the upload in the SWF running in mozilla + firebug for good measure. Things worked great for about 12 images then on the 13th (!!) it froze again. Ive attached a screenshot of the graph from performance mon.
Im guessing I need to do more tests like this to see where there are any problems. Can anyone shed some light on what Im seeing here that might cause problems - the yellow line looks suspicious!(?)
Large green spike corresponds to redrawing the bitmapData I think and the smaller green spike is drawing a thumbnail version from the same Bitmap object after the large version has been successfully loaded. What other counters should I use to monitor memory usage etc.
Any advice is appreciated.
many thanks
You've got too many pixels, that's all.
In Flash Player 10, the maximum number of pixels a bitmap can have si 16,777,215 (or 0xFFFFFF). Also, the maximum width or height is 8,191, as long as the total pixel count is under the maximum value.
Your test bitmap has 21,026,304, which is way over the top.