I'm trying to create a blood effect in my game, to achieve this I need to test whether or not the blood particle hit another instance from an array. I already have the array set up and a way to test if the object is in the array but when i do this:
platform = instance_position(x, y, all);
It will target the blood particle itself while I want the instance underneath. Is there any way of ignoring the blood particle and instead looking at the instance underneath it? I can't change the depth because I do want it to be in the front.
Thanks for your time :)
If you are checking for collision with one particular object or instance, you can use the object name or instance ID in place of the all keyword. Example:
var ins = instance_position(x, y, objWall);
If any instances of objWall are detected, the ID of the first of those instances will be returned. If you use an instance ID instead, only that single instance will be checked for.
If you need to check for multiple different instances, you could loop through the array, performing one check per instance ID and stopping the loop if one of them is found.
If you need to check for multiple object types, you could assign a Parent to those objects and then do a check for the parent. Example: Make four objects, objBallParent, objFootball, objBouncyBall, objCannonBall. In the Object Properties of each ball, set objBallParent as the Parent object.
if ( instance_exists(objBallParent ) {
// Do something
}
var closest = instance_nearest(x, y, objBallParent);
The code above only checks for the parent object, but the functions will be satisfied by any instances of the child objects as well. In this case, if there is an instance of objFootball in the room, that will count as an instance of objBallParent existing, and it can also be returned by the instance_nearest function.
When checking for collisions with objBallParent, any of the three child objects would be accepted by the check.
Related
Suppose I define "Class original:" and create a class attribute "one = 4." Then I create an instance of the class "First = original()." My understanding is that First now contains a pointer to original and "First.one" will return "4." However, suppose I create "Second = original()" and then set "Second.one = 5." What exactly happens in memory? Does a new copy of Class original get created with a class attribute of 5?
I've created a Class original with class attribute one. I then created two instances of this class (First and Second) and verified that id(First.one) and id(Second.one) are pointing to the same place. They both return the same address. However, when I created Third=original() and set Third.one = 5 and then check id(Thrid.one) it appears to be pointing somewhere else. Where is it pointing and what happened? When I check original.one it still returns "4" so obviously the original object is not being modified. Thanks.
It appears you are asking about a piece of code similar to this:
class Original:
def __init__(self, n):
self.one = n
first = Original(4)
second = Original(4)
third = Original(5)
print(id(first.one))
# 140570468047360
print(id(second.one))
# 140570468047360
print(id(third.one))
# 140570468047336
Suppose I define "Class original:" and create a class attribute "one = 4." Then I create an instance of the class "First = original()." My understanding is that First now contains a pointer to original
No. The variable references the instance you created, not the class. If it referenced the class, there would be no way for you to get at the instance you just created.
The instance will, somewhere in its object header, of course contain a pointer to its class. Without that pointer, method lookup wouldn't be possible, since you wouldn't be able to find the class from the instance.
and "First.one" will return "4."
Yes. The attribute one of first contains a pointer to the object 4 (which is an instance of the class int).
[Note that technically, some Python implementations will perform an optimization and actually store the object 4 directly in the attribute instead of a pointer to the object. But that is an internal implementation detail.]
However, suppose I create "Second = original()" and then set "Second.one = 5." What exactly happens in memory? Does a new copy of Class original get created with a class attribute of 5?
No. Why would you need a separate copy of the class? The methods are still the same for both instances. In fact, that is precisely the reason why methods in Python take the instance as their first argument! That way, there need only be one method. (This is actually the same in every OO language, except that in most other languages, this argument is "invisible" and only accessible using a special keyword like self in Ruby, Smalltalk, Self, and Newspeak or this in Java, C#, and Scala.)
I've created a Class original with class attribute one. I then created two instances of this class (First and Second) and verified that id(First.one) and id(Second.one) are pointing to the same place. They both return the same address. However, when I created Third=original() and set Third.one = 5 and then check id(Thrid.one) it appears to be pointing somewhere else.
It is not quite clear to me what your question is here. first.one and second.one both point to 4, so they both point to the same ID since they both point to the same object. third.one points to 5, which is obviously a different object from 4, so naturally, it has a different ID.
It is, in fact, one of the requirement of IDs that different objects that exist at the same time must have different IDs.
Where is it pointing and what happened?
Again, it is not quite clear what you are asking.
It is pointing at 5, and nothing happened.
When I check original.one it still returns "4" so obviously the original object is not being modified.
Indeed, it isn't. Why would it be?
I want to use point picker to pick (get) coordinates of my points in a point cloud. That is why I want to set QPickingSettings to PointPicking but it seems that cannot be done. Events sent to method mouse_event are of type QPickEvent and NOT QPickPointEvent. What am I doing wrong?
self.picker = Qt3DRender.QObjectPicker(self)
picking_settings = Qt3DRender.QPickingSettings(self.picker)
picking_settings.setFaceOrientationPickingMode(
Qt3DRender.QPickingSettings.FrontAndBackFace)
# set QObjectPicker to PointPicking:
picking_settings.setPickMethod(
Qt3DRender.QPickingSettings.PointPicking)
picking_settings.setPickResultMode(
Qt3DRender.QPickingSettings.NearestPick)
picking_settings.setWorldSpaceTolerance(.5)
self.picker.setHoverEnabled(True)
self.picker.setDragEnabled(True)
def mouse_event(e):
# do something
# e should be QPickPointEvent type
pass
self.picker.moved.connect(mouse_event)
self.picker.pressed.connect(mouse_event)
self.picker.clicked.connect(mouse_event)
self.picker.released.connect(mouse_event)
self.addComponent(self.picker)
I'm not familiar with the python API, but you should not create your own instance of QPickingSettings but use the one that exists as a property of the instance of QRenderSettings (that is a singleton).
If you're using the Qt3DWindow from Qt3DExtras, it will provide an accessor to the QRenderSettings instance.
Otherwise, you'll need to create an instance of QRenderSettings and add it as a component of an entity. By convention we tend to use the root of the scene graph.
I'm trying to set up a save function in my HaxeFlixel game.
Some background: The object in question is an instance of Player, which extends FlxSprite. Save data is stored in an instance of a custom class I made for it. That instance is stored in a StringMap (the keys are save names), which is saved by serializing it to a variable in a FlxSave.
Creating the save data and writing it works fine. However, reading the save data back in crashes the game with the message "Invalid field: pixels". pixels is a field from FlxSprite, but it's not the first such field in the serialized string, so it's probably not that.
If it's useful, the declaration of that field is y6:pixelsn - that is:
y begin a field, which is named...
6: a string of length 6...
pixels (the string)
n null
From this line of code you can see that pixels is actually not a variable* at runtime. So the unserializer would crash when it tries to assign value to pixels. But more investigation is need on why the serializer serialized the pixels fields at the first place, because it shouldn't really exist at runtime.
Note*: the accessors of pixels are (get, set), which makes pixels not a real property at runtime. Read more here.
As a general rule, I don't recommend serializing a FlxSprite (or other complex objects) directly. Rather, you should extract the desired information (e.g. x/y position or hp, etc) and serialize only those.
My problem is exactly the same as you can read in this thread:
stackoverflow thread
But there is a small difference. I try to explain it using the above thread's image.
The CS relationship contains C type objects as it is described, but also contains E type objects too, because the E type objects are derived from the C type object.
On thread's image the E type object is not present and this is the difference. The E type property also has a CS relationship.
The problem comes when I try to reach the E type object's CS property using the following query: SUBQUERY(bs, $x, ANY $x.cs.cs ....
The query is not finished, but the important code is there. As I observed, the predicate creation fails, because it tries to use the CS relationship on the C type object. I've tried to use the CAST operator on the $x.cs variable without success.
Do anybody has a clue for this?
Edit: Added image
The values of the MKMultiAttribute entity can contain MKAttribute and MKMultiAttribute types. And this is the problem, because the values is set to be a relationship to MKAttribute, but, because MKMultiAttribute is derived from MKAttribute the values can contain MKMultiAttribute entities and currently I can't call the values again.
I have to model a system where an object of the class Person will invoke the static method getBook(...) : Book on the class Book which will return an instance of a particular book.
How do you reference the book instance obtained by the operation?
As of now, I can think of two approaches, neither of which I have ever seen/used, which is why I am looking for the correct approach.
The first approach is to invoke methods directly on the book instance obtained, e.g. if the reference returned by getBook(...) : Book is named matchingBook, I would use matchingBook.doSomething(...), much like having a local variable.
The second way, which I find more in the line of sequence diagrams is to let the book instance returned by the operation appear with its own lifeline, e.g. next to the Book class, and referencing it with an arrow labeled doSomething(...).
However, with the second approach, it is not that obvious that this object is in fact the one returned by the operation.
The second approach is the correct. To show that you are pointing to the returned object (matchingBook), you can add the variable name to the title of the lifeline, like this:
The second approach is the correct one. Anytime you call operations on an object returned by a first operation, you can't do better than a name match between the result of the first call and the lifeline.
Anyway I don't really understand what you expect of the first way: where would you put matchingBook.doSomething(...)? on a arrow pointing which lifeline?