ShapeRenderer camera - camera

I'm working on platformer game (900x700). And I want to render rectangle (enemy) using ShapeRenderer but I don't see the renctangle.
for(GameObject t : enemies){
if(t instanceof Enemy){
t.update(Gdx.graphics.getDeltaTime());
render.rect(t.getHitBox().getX(), t.getHitBox().getY(), enemies.get(0).getHitBox().width, enemies.get(0).getHitBox().height);
}
}
I understand that somehow I need to convert Screen coords to World Coords. I try to use
camera.unproject();
But I need Vector3 as argument. So how can I get Vector3?

I know the answer. I need to use render.setProjectionMatrix(camera.combined); and all works great! :)

Related

ArcGIS 3.28, clear() except specific graphics

In ArcGIS 3.28, I need to use clear() but exclude some graphics, is there a method to do this? I don't want to remove all the graphics on a layer
Well, ArcGIS JS API provides two way to remove the graphics:
clear() click here for more details...
remove(graphic) click here for more details...
In both the cases there is no provision to provide remove condition so I don't think you can directly remove the the feature base on certain condition.
However still if you need to achieve this below is the same for it-
var graphicsList = layerObj.graphics;
for (i = 0; i < graphicsList.length; i++) {
if(remove_conditions){
layerObj.remove(graphicsList[i]);
i--;
}
}
Hoping above sample will help you to achieve the same.

Fastest way to resize (zoom) a group of sprites in cocos2d

I wanna to zoom a group of about 10 sprites at the same time. The sprites are different sprite layers with transparent background.
I'm trying to preattach all the sprite at first to the layer and store the reference in an array. After that as I click the button I do this:
Sorry this is Javascript but in Objective-C it's almost the same.
attr.zoomAllVisibleSprites = function() {
for (var i = 0; i < this.SpriteArray.length; i++) {
if (this.SpriteArray[i].isVisible()) {
this.SpriteArray[i].setAnchorPoint(cc.PointMake(0.5,0.5));
this.SpriteArray[i].setScale(2, 2);
}
}
}
The execution of this little snippet requires on my Android phone about 2-3 seconds which is too much for my game. Is there a way to do it faster, optimize this code. Maybe group in a different way the sprites could help ?
You could replace your array of sprites by using a for-loop for all CCSprites, like this:
for(CCSprite *sprite in self.view.subviews){ //or scenes or whatever
if([sprite isMemberOfClass:[CCSprite class]]){
//Do your thing }}
Might not help alot, but you can atleast ditch the array ;D
It might be the case that device runs out of memory, try switching to 16-bit textures, it can be done by adding this line on start:
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
Also you can unload unneeded textures before load new scene, like this:
CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames();
CCTextureCache::sharedTextureCache()->removeUnusedTextures();
CCDirector::sharedDirector()->purgeCachedData();
If that doesn't work then it might be a issue with Open-GL, in that case you should have a look at this. It worked like a magic trick for me.
All the Best.. :)

ExpandableListView in iOS

I am trying to get my brain around what I can and can't reasonably do UI-wise in a multi-platform app. Initially we are only concerned about iOS and Android, but may need a mobile Windows version eventually.
The specific question is: How do I replicate the Android ExpandableListView functionality in iOS? I've tried a few searches, but haven't found a hint. The key I need is collapsible sections. Is that doable with an iOS listview? If so, do you have/know of an example?
The related non-specific question is: What advice do you have for someone just starting out developing in multimobilemono? I've been working from Greg Shackles' excellent book, "Mobile Development in C#" (which has been wildly helpful!), so I've got some basics. But I'm sure there are some hidden landmines when you get into more complex UI design. Any advice would be greatly appreciated.
Thank you!
You can use the UITableView, and merely change the size of your cell to display more content as needed.
Let us discuss DialogViewController (part of MonoTouch.Dialog) which simplifies the setup of a UITableView.
What you could do is create a UIView that contains both the content, and the expanded content. It would be controller with some property, for example:
bool expanded;
public bool Expanded { get { return expanded; }}
set {
if (expanded == value)
return;
Frame = ComputeSize (value);
expanded = value;
}
}
Then, create a UIViewElement:
new RootElement ("My Root") {
new Section () {
new UIViewElement (new MyView ());
}
}
For your first question, perhaps you could try :
https://github.com/OliverLetterer/SLExpandableTableView

Mac Mouse/Trackpad Speed Programmatically

I'm trying to change the mouse tracking speed (Notice: Not acceleration) for an application I'm working on. I've searched everywhere for a way to do this, but couldn't find anything.
I suspect that has to do with the value I give in this function on the IOKit/hidsystem Framework:
IOHIDSetAccelerationWithKey(handle, CFSTR(kIOHIDMouseAccelerationType), mouseAcceleration);
Being mouseAcceleration the value, I suspect there is a hex value that defines both acceleration and speed.
Does anyone came across this problem and could help me?
Thanks in advance
Working example in swift:
func getAcceleration() -> Double {
var speed:Double = 0
IOHIDGetAccelerationWithKey(NXOpenEventStatus(), kIOHIDTrackpadAccelerationType, &speed)
return speed
}
func setAcceleration(_ speed: Double) {
IOHIDSetAccelerationWithKey(NXOpenEventStatus(), kIOHIDTrackpadAccelerationType, speed)
}
Source:
http://lists.apple.com/archives/usb/2004/Aug/msg00056.html
You can try to make NSTrackingArea and change mouse position after you get new mouse position.

GraphKit framework in Cocoa

I try to draw an XY graph using GraphKit.
Information of this framework is very limited on the internet...
Here's what I did:
// a xychart is predefined in header as GRChart
GRDateSet *dataset = [[GRXYDataSet alloc] initWithOwnerChart:xychart];
[xychart addDataSet:dataSet loadData:YES];
[xychart reloaddata];
also I implement delegate methods:
(double)chart:(GRChartView *)aChart xValueForDataSet:(GFDataSet*)aDataSet element:(NSUInteger)index
{ return index * 10.0; }
(double)chart:(GRChartView *)aChart yValueForDataSet:(GFDataSet*)aDataSet element:(NSUInteger)index
{ return index * 10.0; }
(NSUInteger) chart:(GRChartView *)aChart numberOfElementsForDataSet:(GFDataSet*)aDataSet {
return 10;
}
however, it only draws the axes but no data points at all...
what did I miss here?
thanks!
I got it. This framework only stores data points and draws axes according to the data points. (It automatically calculates the bounds of each axes and zoom into a suitable plot area.)
However, no drawing method is rooted. To get an immediate graph, I have to use GRAreaDataSet, which is a subclass of GRXYDataSet. Then it will draw an area chart.
I also tried out core-plot. But it's more difficult to use to me. I have to calculate the bounds myself; and padding the graph to show the label values of axes. Also, it's not so beautiful if I don't customize the symbols and lines. However, the default GraphKit charting is nice-looking enough. Though it doesn't have a document...
I'll try to write a tutorial of it when I try out everything in it :)